Accueil > > > SHAMAN LIBRAIRIE DE HASH SUPPORTANT SHA1 SHA256 SHA384 SHA512 MD5 BASE64
SHAMAN LIBRAIRIE DE HASH SUPPORTANT SHA1 SHA256 SHA384 SHA512 MD5 BASE64
Information sur la source
Description
Shaman une DLL/SO(pour POSIX) que j'ai ecrit en C pour un autre projet en fac , qui permet de hasher && crypter vos donnes && checksum vos fichiers selon les algorithmes suivant : * SHA1 (MD5 Killer) * SHA256 * SHA384 * SHA512 ==> pour les paranoid comme moi * MD5 RFC 1321 ( ca craint il parait) * Base64 (Apache project) en plus ca inclut quelque fonction utiles comme la genration de RANDOM String && lecture du fichiers ... le fonctionnemnt est simple : * on initialise la DLL/SO grace a InitShaman * on ajoute une chaine a crypter ShaManAdd * on choisi un algo SCT->meth = SHA1_HASH ( voir example ) * on procede au hashage (ShamanHashData && ShaManCheckSum pour les fichiers ) * voila ( voir example ) SHAMAN est portable et marche sur WIN32/64 POSIX(linux/BSD/Solaris/Mac) ==> TESTES && valides
Source
-
- /*
- ShaMan Hash Shared Library (SHA1 SHA256 SHA384 SHA512 MD5 BASE64 + random string generator )
- Copyright (c) 2007 James Mrad (xtremejames183@msn.com)
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
- /*********************************** API ***********************************************************************/
- #ifndef __SHAMAN_H__
- #define __SHAMAN_H__
-
- #include <stdio.h> /* FILE */
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <time.h> /* for srand */
-
- /* local */
- #include "gdefs.h"
- #include "sha1.h"
- #include "sha256.h"
- #include "sha384.h"
- #include "sha512.h"
- #include "md5.h"
- #include "base64.h"
-
- /* pool memory managment */
- #include "pool.h"
- /* portable&&safe snprintf */
- #include "snprintf.h"
-
- #define FILE_HASH_SIZE 65635
-
- #define MAX_HASH_BUFFER SHA512_HASH_SIZE * 5
- #define SHAMAN_OK 0
- #define SHAMAN_VER "Shaman Hash Library V2.1"
-
- typedef enum
- {
- /* supported Method */
- SHA1_HASH,
- SHA256_HASH,
- SHA384_HASH,
- SHA512_HASH,
- MD5_HASH,
- BASE64_HASH /* lol :-) */
-
- }HASHMETH; /* Hash method */
- typedef struct shaman_st
- {
- uint8_t *clear; /* clear chain */
-
- HASHMETH meth;
- FILE *fp;
- pool p;
-
- uint8_t *hash ; /* final hash chain */
-
- uint8_t *version ; /* SHAMAN Version */
- }SHAMAN_CTX;
-
- /**
- * Util codes
- * Generate Random String
- * @param output: data will be copied to output , hide : optional 1/true if yu want to hash it using SHA1
- * @return SHAMAN_OK on succes , -1 on failure
- */
- int GenRandomString(uint8_t *output,unsigned long len);
- /**
- * Read a file and return it as buffer
- * @param open File Pointer
- * @ return a malloced buffer (must be freed) on success , -1 on failure
- */
- uint8_t *XReadFile(FILE *fp);
-
- #if defined _WIN32 || !defined HAVE_BZERO
- /* bzero for NON POSIX */
- void bzero(void *buf, size_t buf_size) ;
- #endif
-
- /* Core Code */
- /**
- * Init ShaMan Context
- * By default HashMethod is SHA256 */
- SHAMAN_CTX * InitShaMan(void);
- /**
- * Prepare string for Hash Operation
- * @param SHAMAN_CTX Not NULL , a cstr (NOT NULL)
- * @return SHAMAN_OK on succes , -1 on failure
- */
- int ShaManAdd(SHAMAN_CTX *sctx,uint8_t *cstr);
- /*
- * Main Hash Processing
- * Hash the clear buffer and copy its hex code to hash(member of CTX)
- * @param CTX with clear buffer (NOT NULL)
- * @return sctx->hash : the HEX Code && SHAMAN_OK on Sucess , -1 on failure
- */
- int ShaManHashData(SHAMAN_CTX *sctx);
- /*
- * Do File Checksum
- * Hash the file named fname (must not exceed < FILE HASH_SIZE )
- * @param CTX all is done done internally
- * @return sctx->hash on sucess , -1 on failure
- */
- int ShaManFileCheckSum(SHAMAN_CTX *sctx,char *fname);
- /*
- * Destructor OO Style
- */
- int DestroyShaMan(SHAMAN_CTX *sctx);
-
-
- #endif
- /******************************** TEST DE L'API ***************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
-
- #include "shaman.h"
-
- int main(int argc,char *argv[])
- {
-
- SHAMAN_CTX *SCT; /* Context ShaMan */
- int res ;
- uint8_t test[512];
- int i;
- char HAMETH[6][10] = { "SHA1","SHA256","SHA384","SHA512","MD5","BASE64" } ;
- /* Init Shaman Library*/
-
- SCT = InitShaMan() ;
-
- if( SCT == NULL)
- {
- puts("Cannot Load ShaMan Library");
- exit(EXIT_FAILURE);
- }
- puts(SCT->version);
-
- /* genrate a random String */
- res = GenRandomString(test,17);
- if(res != SHAMAN_OK)
- {
- puts("Cannot Generate Random String");
- exit(EXIT_FAILURE);
- }
- printf("Random String is %s\n\n",test);
-
-
- /* prepare to hash */
- ShaManAdd(SCT,test);
-
- /* core hash module */
- for(i = 0 ; i<= BASE64_HASH ; i++ )
- {
- SCT->meth = i ;
- res = ShaManHashData(SCT);
-
- if(res != SHAMAN_OK)
- {
- puts("Error While Hasing Data");
- continue ;
- }
- printf("%s Hex Code is:\n\t %s\n\n",HAMETH[i],SCT->hash);
-
- }
-
- SCT->meth = SHA1_HASH;
- ShaManFileCheckSum(SCT,"./license.txt");
- printf("License.txt Checksum(SHA1): %s\n",SCT->hash);
- SCT->meth = SHA256_HASH;
- ShaManFileCheckSum(SCT,"./license.txt");
- printf("License.txt Checksum(SHA256): %s\n",SCT->hash);
- SCT->meth = MD5_HASH;
- ShaManFileCheckSum(SCT,"./license.txt");
- printf("License.txt Checksum(MD5): %s\n",SCT->hash);
-
-
- DestroyShaMan(SCT);
-
- system("PAUSE");
- return 0;
- }
/*
ShaMan Hash Shared Library (SHA1 SHA256 SHA384 SHA512 MD5 BASE64 + random string generator )
Copyright (c) 2007 James Mrad (xtremejames183@msn.com)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*********************************** API ***********************************************************************/
#ifndef __SHAMAN_H__
#define __SHAMAN_H__
#include <stdio.h> /* FILE */
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h> /* for srand */
/* local */
#include "gdefs.h"
#include "sha1.h"
#include "sha256.h"
#include "sha384.h"
#include "sha512.h"
#include "md5.h"
#include "base64.h"
/* pool memory managment */
#include "pool.h"
/* portable&&safe snprintf */
#include "snprintf.h"
#define FILE_HASH_SIZE 65635
#define MAX_HASH_BUFFER SHA512_HASH_SIZE * 5
#define SHAMAN_OK 0
#define SHAMAN_VER "Shaman Hash Library V2.1"
typedef enum
{
/* supported Method */
SHA1_HASH,
SHA256_HASH,
SHA384_HASH,
SHA512_HASH,
MD5_HASH,
BASE64_HASH /* lol :-) */
}HASHMETH; /* Hash method */
typedef struct shaman_st
{
uint8_t *clear; /* clear chain */
HASHMETH meth;
FILE *fp;
pool p;
uint8_t *hash ; /* final hash chain */
uint8_t *version ; /* SHAMAN Version */
}SHAMAN_CTX;
/**
* Util codes
* Generate Random String
* @param output: data will be copied to output , hide : optional 1/true if yu want to hash it using SHA1
* @return SHAMAN_OK on succes , -1 on failure
*/
int GenRandomString(uint8_t *output,unsigned long len);
/**
* Read a file and return it as buffer
* @param open File Pointer
* @ return a malloced buffer (must be freed) on success , -1 on failure
*/
uint8_t *XReadFile(FILE *fp);
#if defined _WIN32 || !defined HAVE_BZERO
/* bzero for NON POSIX */
void bzero(void *buf, size_t buf_size) ;
#endif
/* Core Code */
/**
* Init ShaMan Context
* By default HashMethod is SHA256 */
SHAMAN_CTX * InitShaMan(void);
/**
* Prepare string for Hash Operation
* @param SHAMAN_CTX Not NULL , a cstr (NOT NULL)
* @return SHAMAN_OK on succes , -1 on failure
*/
int ShaManAdd(SHAMAN_CTX *sctx,uint8_t *cstr);
/*
* Main Hash Processing
* Hash the clear buffer and copy its hex code to hash(member of CTX)
* @param CTX with clear buffer (NOT NULL)
* @return sctx->hash : the HEX Code && SHAMAN_OK on Sucess , -1 on failure
*/
int ShaManHashData(SHAMAN_CTX *sctx);
/*
* Do File Checksum
* Hash the file named fname (must not exceed < FILE HASH_SIZE )
* @param CTX all is done done internally
* @return sctx->hash on sucess , -1 on failure
*/
int ShaManFileCheckSum(SHAMAN_CTX *sctx,char *fname);
/*
* Destructor OO Style
*/
int DestroyShaMan(SHAMAN_CTX *sctx);
#endif
/******************************** TEST DE L'API ***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "shaman.h"
int main(int argc,char *argv[])
{
SHAMAN_CTX *SCT; /* Context ShaMan */
int res ;
uint8_t test[512];
int i;
char HAMETH[6][10] = { "SHA1","SHA256","SHA384","SHA512","MD5","BASE64" } ;
/* Init Shaman Library*/
SCT = InitShaMan() ;
if( SCT == NULL)
{
puts("Cannot Load ShaMan Library");
exit(EXIT_FAILURE);
}
puts(SCT->version);
/* genrate a random String */
res = GenRandomString(test,17);
if(res != SHAMAN_OK)
{
puts("Cannot Generate Random String");
exit(EXIT_FAILURE);
}
printf("Random String is %s\n\n",test);
/* prepare to hash */
ShaManAdd(SCT,test);
/* core hash module */
for(i = 0 ; i<= BASE64_HASH ; i++ )
{
SCT->meth = i ;
res = ShaManHashData(SCT);
if(res != SHAMAN_OK)
{
puts("Error While Hasing Data");
continue ;
}
printf("%s Hex Code is:\n\t %s\n\n",HAMETH[i],SCT->hash);
}
SCT->meth = SHA1_HASH;
ShaManFileCheckSum(SCT,"./license.txt");
printf("License.txt Checksum(SHA1): %s\n",SCT->hash);
SCT->meth = SHA256_HASH;
ShaManFileCheckSum(SCT,"./license.txt");
printf("License.txt Checksum(SHA256): %s\n",SCT->hash);
SCT->meth = MD5_HASH;
ShaManFileCheckSum(SCT,"./license.txt");
printf("License.txt Checksum(MD5): %s\n",SCT->hash);
DestroyShaMan(SCT);
system("PAUSE");
return 0;
}
Conclusion
voila j'espere que ca seras utiles pour vos ... j'attends vos critiques PS: si ma methode de programmation vous semble bizare (normal elle est inspire de la methode de PROG de Berkeley)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
hash md5 [ par flatou ]
salut a tousje travail sur un projet en c qui doit utiliser le hashage md5. je me suis inspiré donc de cette source (pour faire simple) :http://www.cp
inversion md5 [ par emmatopiak ]
Bonjour J'ai vu qu'un ami a fait un code pour inverser un hash md5, en force brute. Actuellement, c'est en PHP. Je me demandais si ca vaudrait pa
comment faire des hash sous linux? [ par floww154 ]
Bonjour a tous, je suis nouveau sur ce forum je m'intéresse a la cryptographie mais je débute en matère de hashages!je désire faire des hashs du genre
problème pour utiliser une DLL en C [ par aurhas ]
Bonjour, j'ai une DLL FTDI pour laquelle je dispose des fichiers dll, lib et h. J'ai également une doc pour décrire les fonctions, leurs paramètres e
Driver / DLL MySql - impossible de les charger une fois l'appli compilée [ par aforpien ]
Bonsoir à tous, Je développe une petite application en QT et j'utilise des drivers Mysql & Oracle pour me connecter à des bases de données (QMYSQL &
probléme du linkage d'un une dll [ par nfousa ]
bonsoir, Lorsque j'ai générer une A.dll à partir du mon code C qui utilise une B.dll j'ai obtenu EXPORTS .idata$4 @1 DATA . _Z7DllMainP1
problémé avec dll [ par nfousa ]
J'ai génère une A.dll à partir du code C qui fait appelle lui même à B.dll. Le problème est que le A.dll générer et de type "dossier de fichier" et n'
Impossible d'obtenir l'adresse d'une function contenus dans une DLL [ par Nementon ]
Bonjours, Voila le code simple d'une DLL et de son exécutable, compilé sous Visual 2008 et qui pour de sombres raisons plante lamentablement, lorsqu
injection dll qui fait planter le processus cible [ par wisar ]
Salut Alors j'ai récupérer un bout de code pour faire une injection d'une dll dans un processus tout semble bien se passer tout me dit que c'est ok m
Windev / C [ par Toto_15l ]
Bonjour à toute la communauté !! Je développe d'habitude en c# ou vb.NET là on m'a demandé de créer une DLL pour accéder aux connexions ODBC. Mais il
|
Derniers Blogs
[WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7[WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7 par Audrey
Lors de la réalisation de ma 2ème application Windows Phone 7, j'ai souhaité utiliser un WrapPanel pour afficher plusieurs photos. Mais le contrôle WrapPanel ne fait pas parti de la liste des contrôles inclus dans le SDK de la version Beta des outils pour...
Cliquez pour lire la suite de l'article par Audrey [WP7] BESOIN D'AVOIR DES DONNéES EN CACHE[WP7] BESOIN D'AVOIR DES DONNéES EN CACHE par Nicolas
Les développeurs ASP.NET ont l'habitude de mettre des données en cache pour éviter de requêter a chaque fois la base de données. Et il est toujours utilie de penser que vos utilisateurs mobiles n'ont pas troujours une super connexion 3G/WIFI et un for...
Cliquez pour lire la suite de l'article par Nicolas [TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION[TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION par cyril
Lorsque l'on créé un Work Item dans TFS, il est possible de le classer dans un "area" et dans une "iteration". Dans la plupart des types de projet, un "area" correspond à une catégorie, une "iteration" à un numéro de version. Il est possible de cré...
Cliquez pour lire la suite de l'article par cyril SQL : FONCTIONS D'AGRéGATION MIN/MAX ET VALEURS NULLSQL : FONCTIONS D'AGRéGATION MIN/MAX ET VALEURS NULL par coq
Les fonctions d'agrégation comme MIN et MAX ignorent les valeurs NULL présentes dans le jeu de données sur lequel porte leur calcul, d'où le fameux message d'avertissement : Warning: Null value is eliminated by an aggregate or other SET operation...
Cliquez pour lire la suite de l'article par coq VOTEZ POUR WARNYGOVOTEZ POUR WARNYGO par Nicolas
La vidéo du projet Warnygo est disponible sur facebook et attend vos votes ! Pour rappel: Warnygo est une application Windows Phone 7 qui permet d'alerter tous utilisateurs inscrits qui se trouve dans la zone où se passe l'...
Cliquez pour lire la suite de l'article par Nicolas
Logiciels
sDEVIS-FACTURES vlPRO (3.8.0)SDEVIS-FACTURES VLPRO (3.8.0)sDEVIS-FACTURES vlPRO a été mis au point pour permettre besoins des particuliers, créateurs, entr... Cliquez pour télécharger sDEVIS-FACTURES vlPRO LettresFaciles (5.6.0)LETTRESFACILES (5.6.0)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles MyPlanning 2010 (5.6.0)MYPLANNING 2010 (5.6.0)MyPlanning 2010 permet de créer des plannings sous la représentation de diagrammes. Plannings pré... Cliquez pour télécharger MyPlanning 2010 Emicsoft Mac DVD en iPad Convertisseur (3.1.16)EMICSOFT MAC DVD EN IPAD CONVERTISSEUR (3.1.16)Emicsoft Mac DVD en iPad Convertisseur, logiciel professionnel de convertir les fichiers DVD en i... Cliquez pour télécharger Emicsoft Mac DVD en iPad Convertisseur Emicsoft ipad ménager pour mac (3.1.08)EMICSOFT IPAD MéNAGER POUR MAC (3.1.08)Emicsoft ipad ménager pour mac est spécialement conçu pour les utilisateurs Mac pour copier des f... Cliquez pour télécharger Emicsoft ipad ménager pour mac
|