Преглед изворни кода

add tiny head before file name, functions...

MurphyZhao пре 7 година
родитељ
комит
a9b97cc36c
11 измењених фајлова са 144 додато и 144 уклоњено
  1. 6 6
      include/tiny_aes.h
  2. 2 2
      include/tiny_base64.h
  3. 9 9
      include/tiny_md5.h
  4. 9 9
      include/tiny_sha1.h
  5. 9 9
      include/tiny_sha2.h
  6. 5 5
      include/tinycrypt.h
  7. 12 12
      src/tiny_aes.c
  8. 2 2
      src/tiny_base64.c
  9. 30 30
      src/tiny_md5.c
  10. 30 30
      src/tiny_sha1.c
  11. 30 30
      src/tiny_sha2.c

+ 6 - 6
include/aes.h → include/tiny_aes.h

@@ -47,7 +47,7 @@ typedef struct {
 	int nr;			/*!<  number of rounds  */
 	unsigned long *rk;	/*!<  AES round keys    */
 	unsigned long buf[68];	/*!<  unaligned data    */
-} aes_context;
+} tiny_aes_context;
 
 #ifdef __cplusplus
 extern "C" {
@@ -60,7 +60,7 @@ extern "C" {
 	 * \param key      encryption key
 	 * \param keysize  must be 128, 192 or 256
 	 */
-	void aes_setkey_enc(aes_context * ctx, unsigned char *key, int keysize);
+	void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize);
 
 	/**
 	 * \brief          AES key schedule (decryption)
@@ -69,7 +69,7 @@ extern "C" {
 	 * \param key      decryption key
 	 * \param keysize  must be 128, 192 or 256
 	 */
-	void aes_setkey_dec(aes_context * ctx, unsigned char *key, int keysize);
+	void tiny_aes_setkey_dec(tiny_aes_context * ctx, unsigned char *key, int keysize);
 
 	/**
 	 * \brief          AES-ECB block encryption/decryption
@@ -79,7 +79,7 @@ extern "C" {
 	 * \param input    16-byte input block
 	 * \param output   16-byte output block
 	 */
-	void aes_crypt_ecb(aes_context * ctx,
+	void tiny_aes_crypt_ecb(tiny_aes_context * ctx,
 			   int mode,
 			   unsigned char input[16], unsigned char output[16]);
 
@@ -93,7 +93,7 @@ extern "C" {
 	 * \param input    buffer holding the input data
 	 * \param output   buffer holding the output data
 	 */
-	void aes_crypt_cbc(aes_context * ctx,
+	void tiny_aes_crypt_cbc(tiny_aes_context * ctx,
 			   int mode,
 			   int length,
 			   unsigned char iv[16],
@@ -110,7 +110,7 @@ extern "C" {
 	 * \param input    buffer holding the input data
 	 * \param output   buffer holding the output data
 	 */
-	void aes_crypt_cfb128(aes_context * ctx,
+	void tiny_aes_crypt_cfb128(tiny_aes_context * ctx,
 			      int mode,
 			      int length,
 			      int *iv_off,

+ 2 - 2
include/base64.h → include/tiny_base64.h

@@ -59,7 +59,7 @@ extern "C" {
 	 * \note           Call this function with *dlen = 0 to obtain the
 	 *                 required buffer size in *dlen
 	 */
-	int base64_encode(unsigned char *dst, int *dlen,
+	int tiny_base64_encode(unsigned char *dst, int *dlen,
 			  unsigned char *src, int slen);
 
 	/**
@@ -78,7 +78,7 @@ extern "C" {
 	 * \note           Call this function with *dlen = 0 to obtain the
 	 *                 required buffer size in *dlen
 	 */
-	int base64_decode(unsigned char *dst, int *dlen,
+	int tiny_base64_decode(unsigned char *dst, int *dlen,
 			  unsigned char *src, int slen);
 
 #ifdef __cplusplus

+ 9 - 9
include/md5.h → include/tiny_md5.h

@@ -47,7 +47,7 @@ typedef struct {
 
 	unsigned char ipad[64];	/*!< HMAC: inner padding        */
 	unsigned char opad[64];	/*!< HMAC: outer padding        */
-} md5_context;
+} tiny_md5_context;
 
 #ifdef __cplusplus
 extern "C" {
@@ -58,7 +58,7 @@ extern "C" {
 	 *
 	 * \param ctx      context to be initialized
 	 */
-	void md5_starts(md5_context * ctx);
+	void tiny_md5_starts(tiny_md5_context * ctx);
 
 	/**
 	 * \brief          MD5 process buffer
@@ -67,7 +67,7 @@ extern "C" {
 	 * \param input    buffer holding the  data
 	 * \param ilen     length of the input data
 	 */
-	void md5_update(md5_context * ctx, unsigned char *input, int ilen);
+	void tiny_md5_update(tiny_md5_context * ctx, unsigned char *input, int ilen);
 
 	/**
 	 * \brief          MD5 final digest
@@ -75,7 +75,7 @@ extern "C" {
 	 * \param ctx      MD5 context
 	 * \param output   MD5 checksum result
 	 */
-	void md5_finish(md5_context * ctx, unsigned char output[16]);
+	void tiny_md5_finish(tiny_md5_context * ctx, unsigned char output[16]);
 
 	/**
 	 * \brief          Output = MD5( input buffer )
@@ -84,7 +84,7 @@ extern "C" {
 	 * \param ilen     length of the input data
 	 * \param output   MD5 checksum result
 	 */
-	void md5(unsigned char *input, int ilen, unsigned char output[16]);
+	void tiny_md5(unsigned char *input, int ilen, unsigned char output[16]);
 
 	/**
 	 * \brief          MD5 HMAC context setup
@@ -93,7 +93,7 @@ extern "C" {
 	 * \param key      HMAC secret key
 	 * \param keylen   length of the HMAC key
 	 */
-	void md5_hmac_starts(md5_context * ctx, unsigned char *key, int keylen);
+	void tiny_md5_hmac_starts(tiny_md5_context * ctx, unsigned char *key, int keylen);
 
 	/**
 	 * \brief          MD5 HMAC process buffer
@@ -102,7 +102,7 @@ extern "C" {
 	 * \param input    buffer holding the  data
 	 * \param ilen     length of the input data
 	 */
-	void md5_hmac_update(md5_context * ctx, unsigned char *input, int ilen);
+	void tiny_md5_hmac_update(tiny_md5_context * ctx, unsigned char *input, int ilen);
 
 	/**
 	 * \brief          MD5 HMAC final digest
@@ -110,7 +110,7 @@ extern "C" {
 	 * \param ctx      HMAC context
 	 * \param output   MD5 HMAC checksum result
 	 */
-	void md5_hmac_finish(md5_context * ctx, unsigned char output[16]);
+	void tiny_md5_hmac_finish(tiny_md5_context * ctx, unsigned char output[16]);
 
 	/**
 	 * \brief          Output = HMAC-MD5( hmac key, input buffer )
@@ -121,7 +121,7 @@ extern "C" {
 	 * \param ilen     length of the input data
 	 * \param output   HMAC-MD5 result
 	 */
-	void md5_hmac(unsigned char *key, int keylen,
+	void tiny_md5_hmac(unsigned char *key, int keylen,
 		      unsigned char *input, int ilen, unsigned char output[16]);
 
 #ifdef __cplusplus

+ 9 - 9
include/sha1.h → include/tiny_sha1.h

@@ -47,7 +47,7 @@ typedef struct {
 
 	unsigned char ipad[64];	/*!< HMAC: inner padding        */
 	unsigned char opad[64];	/*!< HMAC: outer padding        */
-} sha1_context;
+} tiny_sha1_context;
 
 #ifdef __cplusplus
 extern "C" {
@@ -58,7 +58,7 @@ extern "C" {
 	 *
 	 * \param ctx      context to be initialized
 	 */
-	void sha1_starts(sha1_context * ctx);
+	void tiny_sha1_starts(tiny_sha1_context * ctx);
 
 	/**
 	 * \brief          SHA-1 process buffer
@@ -67,7 +67,7 @@ extern "C" {
 	 * \param input    buffer holding the  data
 	 * \param ilen     length of the input data
 	 */
-	void sha1_update(sha1_context * ctx, unsigned char *input, int ilen);
+	void tiny_sha1_update(tiny_sha1_context * ctx, unsigned char *input, int ilen);
 
 	/**
 	 * \brief          SHA-1 final digest
@@ -75,7 +75,7 @@ extern "C" {
 	 * \param ctx      SHA-1 context
 	 * \param output   SHA-1 checksum result
 	 */
-	void sha1_finish(sha1_context * ctx, unsigned char output[20]);
+	void tiny_sha1_finish(tiny_sha1_context * ctx, unsigned char output[20]);
 
 	/**
 	 * \brief          Output = SHA-1( input buffer )
@@ -84,7 +84,7 @@ extern "C" {
 	 * \param ilen     length of the input data
 	 * \param output   SHA-1 checksum result
 	 */
-	void sha1(unsigned char *input, int ilen, unsigned char output[20]);
+	void tiny_sha1(unsigned char *input, int ilen, unsigned char output[20]);
 
 	/**
 	 * \brief          SHA-1 HMAC context setup
@@ -93,7 +93,7 @@ extern "C" {
 	 * \param key      HMAC secret key
 	 * \param keylen   length of the HMAC key
 	 */
-	void sha1_hmac_starts(sha1_context * ctx, unsigned char *key,
+	void tiny_sha1_hmac_starts(tiny_sha1_context * ctx, unsigned char *key,
 			      int keylen);
 
 	/**
@@ -103,7 +103,7 @@ extern "C" {
 	 * \param input    buffer holding the  data
 	 * \param ilen     length of the input data
 	 */
-	void sha1_hmac_update(sha1_context * ctx, unsigned char *input,
+	void tiny_sha1_hmac_update(tiny_sha1_context * ctx, unsigned char *input,
 			      int ilen);
 
 	/**
@@ -112,7 +112,7 @@ extern "C" {
 	 * \param ctx      HMAC context
 	 * \param output   SHA-1 HMAC checksum result
 	 */
-	void sha1_hmac_finish(sha1_context * ctx, unsigned char output[20]);
+	void tiny_sha1_hmac_finish(tiny_sha1_context * ctx, unsigned char output[20]);
 
 	/**
 	 * \brief          Output = HMAC-SHA-1( hmac key, input buffer )
@@ -123,7 +123,7 @@ extern "C" {
 	 * \param ilen     length of the input data
 	 * \param output   HMAC-SHA-1 result
 	 */
-	void sha1_hmac(unsigned char *key, int keylen,
+	void tiny_sha1_hmac(unsigned char *key, int keylen,
 		       unsigned char *input, int ilen,
 		       unsigned char output[20]);
 

+ 9 - 9
include/sha2.h → include/tiny_sha2.h

@@ -48,7 +48,7 @@ typedef struct {
 	unsigned char ipad[64];	/*!< HMAC: inner padding        */
 	unsigned char opad[64];	/*!< HMAC: outer padding        */
 	int is224;		/*!< 0 => SHA-256, else SHA-224 */
-} sha2_context;
+} tiny_sha2_context;
 
 #ifdef __cplusplus
 extern "C" {
@@ -60,7 +60,7 @@ extern "C" {
 	 * \param ctx      context to be initialized
 	 * \param is224    0 = use SHA256, 1 = use SHA224
 	 */
-	void sha2_starts(sha2_context * ctx, int is224);
+	void tiny_sha2_starts(tiny_sha2_context * ctx, int is224);
 
 	/**
 	 * \brief          SHA-256 process buffer
@@ -69,7 +69,7 @@ extern "C" {
 	 * \param input    buffer holding the  data
 	 * \param ilen     length of the input data
 	 */
-	void sha2_update(sha2_context * ctx, unsigned char *input, int ilen);
+	void tiny_sha2_update(tiny_sha2_context * ctx, unsigned char *input, int ilen);
 
 	/**
 	 * \brief          SHA-256 final digest
@@ -77,7 +77,7 @@ extern "C" {
 	 * \param ctx      SHA-256 context
 	 * \param output   SHA-224/256 checksum result
 	 */
-	void sha2_finish(sha2_context * ctx, unsigned char output[32]);
+	void tiny_sha2_finish(tiny_sha2_context * ctx, unsigned char output[32]);
 
 	/**
 	 * \brief          Output = SHA-256( input buffer )
@@ -87,7 +87,7 @@ extern "C" {
 	 * \param output   SHA-224/256 checksum result
 	 * \param is224    0 = use SHA256, 1 = use SHA224
 	 */
-	void sha2(unsigned char *input, int ilen,
+	void tiny_sha2(unsigned char *input, int ilen,
 		  unsigned char output[32], int is224);
 
 	/**
@@ -98,7 +98,7 @@ extern "C" {
 	 * \param keylen   length of the HMAC key
 	 * \param is224    0 = use SHA256, 1 = use SHA224
 	 */
-	void sha2_hmac_starts(sha2_context * ctx, unsigned char *key,
+	void tiny_sha2_hmac_starts(tiny_sha2_context * ctx, unsigned char *key,
 			      int keylen, int is224);
 
 	/**
@@ -108,7 +108,7 @@ extern "C" {
 	 * \param input    buffer holding the  data
 	 * \param ilen     length of the input data
 	 */
-	void sha2_hmac_update(sha2_context * ctx, unsigned char *input,
+	void tiny_sha2_hmac_update(tiny_sha2_context * ctx, unsigned char *input,
 			      int ilen);
 
 	/**
@@ -117,7 +117,7 @@ extern "C" {
 	 * \param ctx      HMAC context
 	 * \param output   SHA-224/256 HMAC checksum result
 	 */
-	void sha2_hmac_finish(sha2_context * ctx, unsigned char output[32]);
+	void tiny_sha2_hmac_finish(tiny_sha2_context * ctx, unsigned char output[32]);
 
 	/**
 	 * \brief          Output = HMAC-SHA-256( hmac key, input buffer )
@@ -129,7 +129,7 @@ extern "C" {
 	 * \param output   HMAC-SHA-224/256 result
 	 * \param is224    0 = use SHA256, 1 = use SHA224
 	 */
-	void sha2_hmac(unsigned char *key, int keylen,
+	void tiny_sha2_hmac(unsigned char *key, int keylen,
 		       unsigned char *input, int ilen,
 		       unsigned char output[32], int is224);
 

+ 5 - 5
include/tinycrypt.h

@@ -39,23 +39,23 @@
 #define TINY_CRYPT_H__
 
 #ifdef TINY_CRYPT_MD5
-#include "md5.h"
+#include "tiny_md5.h"
 #endif
 
 #ifdef TINY_CRYPT_AES
-#include "aes.h"
+#include "tiny_aes.h"
 #endif
 
 #ifdef TINY_CRYPT_SHA1
-#include "sha1.h"
+#include "tiny_sha1.h"
 #endif
 
 #ifdef TINY_CRYPT_SHA256
-#include "sha2.h"
+#include "tiny_sha2.h"
 #endif
 
 #ifdef TINY_CRYPT_BASE64
-#include "base64.h"
+#include "tiny_base64.h"
 #endif
 
 #endif

+ 12 - 12
src/aes.c → src/tiny_aes.c

@@ -455,7 +455,7 @@ static void aes_gen_tables(void)
 /*
  * AES key schedule (encryption)
  */
-void aes_setkey_enc(aes_context * ctx, unsigned char *key, int keysize)
+void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize)
 {
 	int i;
 	unsigned long *RK;
@@ -554,10 +554,10 @@ void aes_setkey_enc(aes_context * ctx, unsigned char *key, int keysize)
 /*
  * AES key schedule (decryption)
  */
-void aes_setkey_dec(aes_context * ctx, unsigned char *key, int keysize)
+void tiny_aes_setkey_dec(tiny_aes_context * ctx, unsigned char *key, int keysize)
 {
 	int i, j;
-	aes_context cty;
+	tiny_aes_context cty;
 	unsigned long *RK;
 	unsigned long *SK;
 
@@ -577,7 +577,7 @@ void aes_setkey_dec(aes_context * ctx, unsigned char *key, int keysize)
 
 	ctx->rk = RK = ctx->buf;
 
-	aes_setkey_enc(&cty, key, keysize);
+	tiny_aes_setkey_enc(&cty, key, keysize);
 	SK = cty.rk + cty.nr * 4;
 
 	*RK++ = *SK++;
@@ -599,7 +599,7 @@ void aes_setkey_dec(aes_context * ctx, unsigned char *key, int keysize)
 	*RK++ = *SK++;
 	*RK++ = *SK++;
 
-	memset(&cty, 0, sizeof(aes_context));
+	memset(&cty, 0, sizeof(tiny_aes_context));
 }
 
 #define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3)     \
@@ -651,7 +651,7 @@ void aes_setkey_dec(aes_context * ctx, unsigned char *key, int keysize)
 /*
  * AES-ECB block encryption/decryption
  */
-void aes_crypt_ecb(aes_context * ctx,
+void tiny_aes_crypt_ecb(tiny_aes_context * ctx,
 		   int mode, unsigned char input[16], unsigned char output[16])
 {
 	int i;
@@ -741,7 +741,7 @@ void aes_crypt_ecb(aes_context * ctx,
 /*
  * AES-CBC buffer encryption/decryption
  */
-void aes_crypt_cbc(aes_context * ctx,
+void tiny_aes_crypt_cbc(tiny_aes_context * ctx,
 		   int mode,
 		   int length,
 		   unsigned char iv[16],
@@ -753,7 +753,7 @@ void aes_crypt_cbc(aes_context * ctx,
 	if (mode == AES_DECRYPT) {
 		while (length > 0) {
 			memcpy(temp, input, 16);
-			aes_crypt_ecb(ctx, mode, input, output);
+			tiny_aes_crypt_ecb(ctx, mode, input, output);
 
 			for (i = 0; i < 16; i++)
 				output[i] = (unsigned char)(output[i] ^ iv[i]);
@@ -769,7 +769,7 @@ void aes_crypt_cbc(aes_context * ctx,
 			for (i = 0; i < 16; i++)
 				output[i] = (unsigned char)(input[i] ^ iv[i]);
 
-			aes_crypt_ecb(ctx, mode, output, output);
+			tiny_aes_crypt_ecb(ctx, mode, output, output);
 			memcpy(iv, output, 16);
 
 			input += 16;
@@ -782,7 +782,7 @@ void aes_crypt_cbc(aes_context * ctx,
 /*
  * AES-CFB128 buffer encryption/decryption
  */
-void aes_crypt_cfb128(aes_context * ctx,
+void tiny_aes_crypt_cfb128(tiny_aes_context * ctx,
 		      int mode,
 		      int length,
 		      int *iv_off,
@@ -794,7 +794,7 @@ void aes_crypt_cfb128(aes_context * ctx,
 	if (mode == AES_DECRYPT) {
 		while (length--) {
 			if (n == 0)
-				aes_crypt_ecb(ctx, AES_ENCRYPT, iv, iv);
+				tiny_aes_crypt_ecb(ctx, AES_ENCRYPT, iv, iv);
 
 			c = *input++;
 			*output++ = (unsigned char)(c ^ iv[n]);
@@ -805,7 +805,7 @@ void aes_crypt_cfb128(aes_context * ctx,
 	} else {
 		while (length--) {
 			if (n == 0)
-				aes_crypt_ecb(ctx, AES_ENCRYPT, iv, iv);
+				tiny_aes_crypt_ecb(ctx, AES_ENCRYPT, iv, iv);
 
 			iv[n] = *output++ = (unsigned char)(iv[n] ^ *input++);
 

+ 2 - 2
src/base64.c → src/tiny_base64.c

@@ -70,7 +70,7 @@ static const unsigned char base64_dec_map[128] = {
 /*
  * Encode a buffer into base64 format
  */
-int base64_encode(unsigned char *dst, int *dlen, unsigned char *src, int slen)
+int tiny_base64_encode(unsigned char *dst, int *dlen, unsigned char *src, int slen)
 {
 	int i, n;
 	int C1, C2, C3;
@@ -134,7 +134,7 @@ int base64_encode(unsigned char *dst, int *dlen, unsigned char *src, int slen)
 /*
  * Decode a base64-formatted buffer
  */
-int base64_decode(unsigned char *dst, int *dlen, unsigned char *src, int slen)
+int tiny_base64_decode(unsigned char *dst, int *dlen, unsigned char *src, int slen)
 {
 	int i, j, n;
 	unsigned long x;

+ 30 - 30
src/md5.c → src/tiny_md5.c

@@ -75,7 +75,7 @@
 /*
  * MD5 context setup
  */
-void md5_starts(md5_context * ctx)
+void tiny_md5_starts(tiny_md5_context * ctx)
 {
 	ctx->total[0] = 0;
 	ctx->total[1] = 0;
@@ -86,7 +86,7 @@ void md5_starts(md5_context * ctx)
 	ctx->state[3] = 0x10325476;
 }
 
-static void md5_process(md5_context * ctx, unsigned char data[64])
+static void md5_process(tiny_md5_context * ctx, unsigned char data[64])
 {
 	unsigned long X[16], A, B, C, D;
 
@@ -212,7 +212,7 @@ static void md5_process(md5_context * ctx, unsigned char data[64])
 /*
  * MD5 process buffer
  */
-void md5_update(md5_context * ctx, unsigned char *input, int ilen)
+void tiny_md5_update(tiny_md5_context * ctx, unsigned char *input, int ilen)
 {
 	int fill;
 	unsigned long left;
@@ -258,7 +258,7 @@ static const unsigned char md5_padding[64] = {
 /*
  * MD5 final digest
  */
-void md5_finish(md5_context * ctx, unsigned char output[16])
+void tiny_md5_finish(tiny_md5_context * ctx, unsigned char output[16])
 {
 	unsigned long last, padn;
 	unsigned long high, low;
@@ -274,8 +274,8 @@ void md5_finish(md5_context * ctx, unsigned char output[16])
 	last = ctx->total[0] & 0x3F;
 	padn = (last < 56) ? (56 - last) : (120 - last);
 
-	md5_update(ctx, (unsigned char *)md5_padding, padn);
-	md5_update(ctx, msglen, 8);
+	tiny_md5_update(ctx, (unsigned char *)md5_padding, padn);
+	tiny_md5_update(ctx, msglen, 8);
 
 	PUT_ULONG_LE(ctx->state[0], output, 0);
 	PUT_ULONG_LE(ctx->state[1], output, 4);
@@ -286,27 +286,27 @@ void md5_finish(md5_context * ctx, unsigned char output[16])
 /*
  * output = MD5( input buffer )
  */
-void md5(unsigned char *input, int ilen, unsigned char output[16])
+void tiny_md5(unsigned char *input, int ilen, unsigned char output[16])
 {
-	md5_context ctx;
+	tiny_md5_context ctx;
 
-	md5_starts(&ctx);
-	md5_update(&ctx, input, ilen);
-	md5_finish(&ctx, output);
+	tiny_md5_starts(&ctx);
+	tiny_md5_update(&ctx, input, ilen);
+	tiny_md5_finish(&ctx, output);
 
-	memset(&ctx, 0, sizeof(md5_context));
+	memset(&ctx, 0, sizeof(tiny_md5_context));
 }
 
 /*
  * MD5 HMAC context setup
  */
-void md5_hmac_starts(md5_context * ctx, unsigned char *key, int keylen)
+void tiny_md5_hmac_starts(tiny_md5_context * ctx, unsigned char *key, int keylen)
 {
 	int i;
 	unsigned char sum[16];
 
 	if (keylen > 64) {
-		md5(key, keylen, sum);
+		tiny_md5(key, keylen, sum);
 		keylen = 16;
 		key = sum;
 	}
@@ -319,8 +319,8 @@ void md5_hmac_starts(md5_context * ctx, unsigned char *key, int keylen)
 		ctx->opad[i] = (unsigned char)(ctx->opad[i] ^ key[i]);
 	}
 
-	md5_starts(ctx);
-	md5_update(ctx, ctx->ipad, 64);
+	tiny_md5_starts(ctx);
+	tiny_md5_update(ctx, ctx->ipad, 64);
 
 	memset(sum, 0, sizeof(sum));
 }
@@ -328,23 +328,23 @@ void md5_hmac_starts(md5_context * ctx, unsigned char *key, int keylen)
 /*
  * MD5 HMAC process buffer
  */
-void md5_hmac_update(md5_context * ctx, unsigned char *input, int ilen)
+void tiny_md5_hmac_update(tiny_md5_context * ctx, unsigned char *input, int ilen)
 {
-	md5_update(ctx, input, ilen);
+	tiny_md5_update(ctx, input, ilen);
 }
 
 /*
  * MD5 HMAC final digest
  */
-void md5_hmac_finish(md5_context * ctx, unsigned char output[16])
+void tiny_md5_hmac_finish(tiny_md5_context * ctx, unsigned char output[16])
 {
 	unsigned char tmpbuf[16];
 
-	md5_finish(ctx, tmpbuf);
-	md5_starts(ctx);
-	md5_update(ctx, ctx->opad, 64);
-	md5_update(ctx, tmpbuf, 16);
-	md5_finish(ctx, output);
+	tiny_md5_finish(ctx, tmpbuf);
+	tiny_md5_starts(ctx);
+	tiny_md5_update(ctx, ctx->opad, 64);
+	tiny_md5_update(ctx, tmpbuf, 16);
+	tiny_md5_finish(ctx, output);
 
 	memset(tmpbuf, 0, sizeof(tmpbuf));
 }
@@ -352,16 +352,16 @@ void md5_hmac_finish(md5_context * ctx, unsigned char output[16])
 /*
  * output = HMAC-MD5( hmac key, input buffer )
  */
-void md5_hmac(unsigned char *key, int keylen, unsigned char *input, int ilen,
+void tiny_md5_hmac(unsigned char *key, int keylen, unsigned char *input, int ilen,
 	      unsigned char output[16])
 {
-	md5_context ctx;
+	tiny_md5_context ctx;
 
-	md5_hmac_starts(&ctx, key, keylen);
-	md5_hmac_update(&ctx, input, ilen);
-	md5_hmac_finish(&ctx, output);
+	tiny_md5_hmac_starts(&ctx, key, keylen);
+	tiny_md5_hmac_update(&ctx, input, ilen);
+	tiny_md5_hmac_finish(&ctx, output);
 
-	memset(&ctx, 0, sizeof(md5_context));
+	memset(&ctx, 0, sizeof(tiny_md5_context));
 }
 
 #endif

+ 30 - 30
src/sha1.c → src/tiny_sha1.c

@@ -75,7 +75,7 @@
 /*
  * SHA-1 context setup
  */
-void sha1_starts(sha1_context * ctx)
+void tiny_sha1_starts(tiny_sha1_context * ctx)
 {
 	ctx->total[0] = 0;
 	ctx->total[1] = 0;
@@ -87,7 +87,7 @@ void sha1_starts(sha1_context * ctx)
 	ctx->state[4] = 0xC3D2E1F0;
 }
 
-static void sha1_process(sha1_context * ctx, unsigned char data[64])
+static void sha1_process(tiny_sha1_context * ctx, unsigned char data[64])
 {
 	unsigned long temp, W[16], A, B, C, D, E;
 
@@ -246,7 +246,7 @@ static void sha1_process(sha1_context * ctx, unsigned char data[64])
 /*
  * SHA-1 process buffer
  */
-void sha1_update(sha1_context * ctx, unsigned char *input, int ilen)
+void tiny_sha1_update(tiny_sha1_context * ctx, unsigned char *input, int ilen)
 {
 	int fill;
 	unsigned long left;
@@ -292,7 +292,7 @@ static const unsigned char sha1_padding[64] = {
 /*
  * SHA-1 final digest
  */
-void sha1_finish(sha1_context * ctx, unsigned char output[20])
+void tiny_sha1_finish(tiny_sha1_context * ctx, unsigned char output[20])
 {
 	unsigned long last, padn;
 	unsigned long high, low;
@@ -308,8 +308,8 @@ void sha1_finish(sha1_context * ctx, unsigned char output[20])
 	last = ctx->total[0] & 0x3F;
 	padn = (last < 56) ? (56 - last) : (120 - last);
 
-	sha1_update(ctx, (unsigned char *)sha1_padding, padn);
-	sha1_update(ctx, msglen, 8);
+	tiny_sha1_update(ctx, (unsigned char *)sha1_padding, padn);
+	tiny_sha1_update(ctx, msglen, 8);
 
 	PUT_ULONG_BE(ctx->state[0], output, 0);
 	PUT_ULONG_BE(ctx->state[1], output, 4);
@@ -321,27 +321,27 @@ void sha1_finish(sha1_context * ctx, unsigned char output[20])
 /*
  * output = SHA-1( input buffer )
  */
-void sha1(unsigned char *input, int ilen, unsigned char output[20])
+void tiny_sha1(unsigned char *input, int ilen, unsigned char output[20])
 {
-	sha1_context ctx;
+	tiny_sha1_context ctx;
 
-	sha1_starts(&ctx);
-	sha1_update(&ctx, input, ilen);
-	sha1_finish(&ctx, output);
+	tiny_sha1_starts(&ctx);
+	tiny_sha1_update(&ctx, input, ilen);
+	tiny_sha1_finish(&ctx, output);
 
-	memset(&ctx, 0, sizeof(sha1_context));
+	memset(&ctx, 0, sizeof(tiny_sha1_context));
 }
 
 /*
  * SHA-1 HMAC context setup
  */
-void sha1_hmac_starts(sha1_context * ctx, unsigned char *key, int keylen)
+void tiny_sha1_hmac_starts(tiny_sha1_context * ctx, unsigned char *key, int keylen)
 {
 	int i;
 	unsigned char sum[20];
 
 	if (keylen > 64) {
-		sha1(key, keylen, sum);
+		tiny_sha1(key, keylen, sum);
 		keylen = 20;
 		key = sum;
 	}
@@ -354,8 +354,8 @@ void sha1_hmac_starts(sha1_context * ctx, unsigned char *key, int keylen)
 		ctx->opad[i] = (unsigned char)(ctx->opad[i] ^ key[i]);
 	}
 
-	sha1_starts(ctx);
-	sha1_update(ctx, ctx->ipad, 64);
+	tiny_sha1_starts(ctx);
+	tiny_sha1_update(ctx, ctx->ipad, 64);
 
 	memset(sum, 0, sizeof(sum));
 }
@@ -363,23 +363,23 @@ void sha1_hmac_starts(sha1_context * ctx, unsigned char *key, int keylen)
 /*
  * SHA-1 HMAC process buffer
  */
-void sha1_hmac_update(sha1_context * ctx, unsigned char *input, int ilen)
+void tiny_sha1_hmac_update(tiny_sha1_context * ctx, unsigned char *input, int ilen)
 {
-	sha1_update(ctx, input, ilen);
+	tiny_sha1_update(ctx, input, ilen);
 }
 
 /*
  * SHA-1 HMAC final digest
  */
-void sha1_hmac_finish(sha1_context * ctx, unsigned char output[20])
+void tiny_sha1_hmac_finish(tiny_sha1_context * ctx, unsigned char output[20])
 {
 	unsigned char tmpbuf[20];
 
-	sha1_finish(ctx, tmpbuf);
-	sha1_starts(ctx);
-	sha1_update(ctx, ctx->opad, 64);
-	sha1_update(ctx, tmpbuf, 20);
-	sha1_finish(ctx, output);
+	tiny_sha1_finish(ctx, tmpbuf);
+	tiny_sha1_starts(ctx);
+	tiny_sha1_update(ctx, ctx->opad, 64);
+	tiny_sha1_update(ctx, tmpbuf, 20);
+	tiny_sha1_finish(ctx, output);
 
 	memset(tmpbuf, 0, sizeof(tmpbuf));
 }
@@ -387,16 +387,16 @@ void sha1_hmac_finish(sha1_context * ctx, unsigned char output[20])
 /*
  * output = HMAC-SHA-1( hmac key, input buffer )
  */
-void sha1_hmac(unsigned char *key, int keylen,
+void tiny_sha1_hmac(unsigned char *key, int keylen,
 	       unsigned char *input, int ilen, unsigned char output[20])
 {
-	sha1_context ctx;
+	tiny_sha1_context ctx;
 
-	sha1_hmac_starts(&ctx, key, keylen);
-	sha1_hmac_update(&ctx, input, ilen);
-	sha1_hmac_finish(&ctx, output);
+	tiny_sha1_hmac_starts(&ctx, key, keylen);
+	tiny_sha1_hmac_update(&ctx, input, ilen);
+	tiny_sha1_hmac_finish(&ctx, output);
 
-	memset(&ctx, 0, sizeof(sha1_context));
+	memset(&ctx, 0, sizeof(tiny_sha1_context));
 }
 
 #endif

+ 30 - 30
src/sha2.c → src/tiny_sha2.c

@@ -75,7 +75,7 @@
 /*
  * SHA-256 context setup
  */
-void sha2_starts(sha2_context * ctx, int is224)
+void tiny_sha2_starts(tiny_sha2_context * ctx, int is224)
 {
 	ctx->total[0] = 0;
 	ctx->total[1] = 0;
@@ -105,7 +105,7 @@ void sha2_starts(sha2_context * ctx, int is224)
 	ctx->is224 = is224;
 }
 
-static void sha2_process(sha2_context * ctx, unsigned char data[64])
+static void sha2_process(tiny_sha2_context * ctx, unsigned char data[64])
 {
 	unsigned long temp1, temp2, W[64];
 	unsigned long A, B, C, D, E, F, G, H;
@@ -239,7 +239,7 @@ static void sha2_process(sha2_context * ctx, unsigned char data[64])
 /*
  * SHA-256 process buffer
  */
-void sha2_update(sha2_context * ctx, unsigned char *input, int ilen)
+void tiny_sha2_update(tiny_sha2_context * ctx, unsigned char *input, int ilen)
 {
 	int fill;
 	unsigned long left;
@@ -285,7 +285,7 @@ static const unsigned char sha2_padding[64] = {
 /*
  * SHA-256 final digest
  */
-void sha2_finish(sha2_context * ctx, unsigned char output[32])
+void tiny_sha2_finish(tiny_sha2_context * ctx, unsigned char output[32])
 {
 	unsigned long last, padn;
 	unsigned long high, low;
@@ -301,8 +301,8 @@ void sha2_finish(sha2_context * ctx, unsigned char output[32])
 	last = ctx->total[0] & 0x3F;
 	padn = (last < 56) ? (56 - last) : (120 - last);
 
-	sha2_update(ctx, (unsigned char *)sha2_padding, padn);
-	sha2_update(ctx, msglen, 8);
+	tiny_sha2_update(ctx, (unsigned char *)sha2_padding, padn);
+	tiny_sha2_update(ctx, msglen, 8);
 
 	PUT_ULONG_BE(ctx->state[0], output, 0);
 	PUT_ULONG_BE(ctx->state[1], output, 4);
@@ -319,28 +319,28 @@ void sha2_finish(sha2_context * ctx, unsigned char output[32])
 /*
  * output = SHA-256( input buffer )
  */
-void sha2(unsigned char *input, int ilen, unsigned char output[32], int is224)
+void tiny_sha2(unsigned char *input, int ilen, unsigned char output[32], int is224)
 {
-	sha2_context ctx;
+	tiny_sha2_context ctx;
 
-	sha2_starts(&ctx, is224);
-	sha2_update(&ctx, input, ilen);
-	sha2_finish(&ctx, output);
+	tiny_sha2_starts(&ctx, is224);
+	tiny_sha2_update(&ctx, input, ilen);
+	tiny_sha2_finish(&ctx, output);
 
-	memset(&ctx, 0, sizeof(sha2_context));
+	memset(&ctx, 0, sizeof(tiny_sha2_context));
 }
 
 /*
  * SHA-256 HMAC context setup
  */
-void sha2_hmac_starts(sha2_context * ctx, unsigned char *key, int keylen,
+void tiny_sha2_hmac_starts(tiny_sha2_context * ctx, unsigned char *key, int keylen,
 		      int is224)
 {
 	int i;
 	unsigned char sum[32];
 
 	if (keylen > 64) {
-		sha2(key, keylen, sum, is224);
+		tiny_sha2(key, keylen, sum, is224);
 		keylen = (is224) ? 28 : 32;
 		key = sum;
 	}
@@ -353,8 +353,8 @@ void sha2_hmac_starts(sha2_context * ctx, unsigned char *key, int keylen,
 		ctx->opad[i] = (unsigned char)(ctx->opad[i] ^ key[i]);
 	}
 
-	sha2_starts(ctx, is224);
-	sha2_update(ctx, ctx->ipad, 64);
+	tiny_sha2_starts(ctx, is224);
+	tiny_sha2_update(ctx, ctx->ipad, 64);
 
 	memset(sum, 0, sizeof(sum));
 }
@@ -362,15 +362,15 @@ void sha2_hmac_starts(sha2_context * ctx, unsigned char *key, int keylen,
 /*
  * SHA-256 HMAC process buffer
  */
-void sha2_hmac_update(sha2_context * ctx, unsigned char *input, int ilen)
+void tiny_sha2_hmac_update(tiny_sha2_context * ctx, unsigned char *input, int ilen)
 {
-	sha2_update(ctx, input, ilen);
+	tiny_sha2_update(ctx, input, ilen);
 }
 
 /*
  * SHA-256 HMAC final digest
  */
-void sha2_hmac_finish(sha2_context * ctx, unsigned char output[32])
+void tiny_sha2_hmac_finish(tiny_sha2_context * ctx, unsigned char output[32])
 {
 	int is224, hlen;
 	unsigned char tmpbuf[32];
@@ -378,11 +378,11 @@ void sha2_hmac_finish(sha2_context * ctx, unsigned char output[32])
 	is224 = ctx->is224;
 	hlen = (is224 == 0) ? 32 : 28;
 
-	sha2_finish(ctx, tmpbuf);
-	sha2_starts(ctx, is224);
-	sha2_update(ctx, ctx->opad, 64);
-	sha2_update(ctx, tmpbuf, hlen);
-	sha2_finish(ctx, output);
+	tiny_sha2_finish(ctx, tmpbuf);
+	tiny_sha2_starts(ctx, is224);
+	tiny_sha2_update(ctx, ctx->opad, 64);
+	tiny_sha2_update(ctx, tmpbuf, hlen);
+	tiny_sha2_finish(ctx, output);
 
 	memset(tmpbuf, 0, sizeof(tmpbuf));
 }
@@ -390,17 +390,17 @@ void sha2_hmac_finish(sha2_context * ctx, unsigned char output[32])
 /*
  * output = HMAC-SHA-256( hmac key, input buffer )
  */
-void sha2_hmac(unsigned char *key, int keylen,
+void tiny_sha2_hmac(unsigned char *key, int keylen,
 	       unsigned char *input, int ilen,
 	       unsigned char output[32], int is224)
 {
-	sha2_context ctx;
+	tiny_sha2_context ctx;
 
-	sha2_hmac_starts(&ctx, key, keylen, is224);
-	sha2_hmac_update(&ctx, input, ilen);
-	sha2_hmac_finish(&ctx, output);
+	tiny_sha2_hmac_starts(&ctx, key, keylen, is224);
+	tiny_sha2_hmac_update(&ctx, input, ilen);
+	tiny_sha2_hmac_finish(&ctx, output);
 
-	memset(&ctx, 0, sizeof(sha2_context));
+	memset(&ctx, 0, sizeof(tiny_sha2_context));
 }
 
 #endif