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
vc2005 dll [ par lilington ]
Bonjourvoila je viens d'installer msvc2005 le probleme c'est que je ne peux pas executer mes prog.je recois un message windows disant que la dll:msvcr
comment créer une dll en vc++ 2005 [ par lhoua94 ]
Bonjour,Je souhaite créer une DLL en VC++ 2005 pour un pocket pc 2005 ou un smartphone que l'on puisse appeler depuis un autre projet sous WINDEV .
comment créer une dll en vc 2005 [ par lhoua94 ]
Bonjour,Je souhaite créer une DLL en VC++ 2005 pour un pocket pc 2005 ou un smartphone que l'on puisse appeler depuis un a
DLL windows [ par zoomeo ]
Salut les gars!Je dois bosser sur un prog et j'aimerai avoir des precisions car c'est un peu confu tout ca pour moi...En gros, pour mon programme, je
dll pour vb6 [ par draluorg ]
Salut a tous,J'essai de faire une dll en C pour utiliser sous vb6, mais je recois toujours le message "Bad dll Calling Convention" depuis vb6 :(Voici
utilisation d'une dll.net en C [ par thmatew ]
Bonjour a tous,Voila mon souci, j'ai besoin d'intégrer une dll.NET en C, j'aimerais savoir comment faire pour utiliser cette dll???!!!!j'utilise Visua
importer une dll [ par omtp13 ]
Salut tout le monde,je désire importer les fonctions d'une dll pour que ces fonctions puissent être utilisées dans le code d'une seconde dll.j'ai ente
Executer une dll comme un programme? [ par Neo_Fr ]
Salut,Est - il possible d'éxecuter une dll comme un programme?Si oui comment?Neo_Fr
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : WIN APIRE : WIN API par racpp
Cliquez pour lire la suite par racpp
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|