]> foleosoft.com Git - CryptoFoleo.git/commitdiff
Fri Aug 11 03:07:21 PM EDT 2023
authorserver <[email protected]>
Fri, 11 Aug 2023 19:07:21 +0000 (15:07 -0400)
committerserver <[email protected]>
Fri, 11 Aug 2023 19:07:21 +0000 (15:07 -0400)
src/hmac.c
tests/cases.c
tests/test.c

index 60ca0c90896cb4eb303495b7a6a8b707e39882ff..abae1456113276ad560998076332594ae7523a0a 100644 (file)
@@ -44,7 +44,7 @@ uint8_t* foleo_hmac
         }
         free(tmp1);
     }
-    
     //opad and ipad
     uint8_t opad[Bs];
     uint8_t ipad[Bs];
@@ -72,7 +72,7 @@ uint8_t* foleo_hmac
     tmp2 = hash_func(tmp1, Bs + Hs);
     free(tmp1);
     return tmp2;
-    
+
 }
 
 //A(0) = seed
@@ -138,34 +138,35 @@ uint8_t* foleo_hmac_prf
     Hs = foleo_hash_size(hfunc);
     Bs = foleo_hash_blocksize(hfunc);
 
-    uint32_t iter = 1;
+    uint32_t iter = 0;
     uint8_t* keystream = malloc(0);
     uint8_t* labelSeed = malloc(labelS + seedS);
 
     for (uint32_t i = 0; i < labelS + seedS; i++)
         labelSeed[i] = i < labelS ? label[i] : seed[i - labelS];
-    
+
     while (desiredBytes != 0)
     {
         uint32_t tmp1S;
-        uint8_t* tmp1 = foleo_hmac_A(hfunc, iter, secret, secretS, labelSeed, labelS + seedS, &tmp1S);
+        uint8_t* tmp1 = foleo_hmac_A(hfunc, iter + 1, secret, secretS, labelSeed, labelS + seedS, &tmp1S);
         tmp1 = realloc(tmp1, tmp1S + labelS + seedS);
         for (uint32_t i = 0; i < labelS + seedS; i++)
             tmp1[i + tmp1S] = labelSeed[i];
         uint8_t* tmp2 = foleo_hmac(hfunc, secret, secretS, tmp1, tmp1S + labelS + seedS);
         free(tmp1);
-        if (desiredBytes >= Bs)
+
+        if (desiredBytes >= Hs)
         {
-            keystream = realloc(keystream, iter * Bs);
-            for (uint32_t i = 0; i < Bs; i++)
-                keystream[i + (iter - 1) * Bs] = tmp2[i];
-            desiredBytes -= Bs;
+            keystream = realloc(keystream, (iter + 1) * Hs);
+            for (uint32_t i = 0; i < Hs; i++)
+                keystream[i + iter * Hs] = tmp2[i];
+            desiredBytes -= Hs;
         }
         else
         {
-            keystream = realloc(keystream, (iter - 1) * Bs + desiredBytes);
+            keystream = realloc(keystream, iter * Hs + desiredBytes);
             for (uint32_t i = 0; i < desiredBytes; i++)
-                keystream[i + (iter - 1) * Bs] = tmp2[i];
+                keystream[i + iter* Hs] = tmp2[i];
             desiredBytes = 0;
         }
         free(tmp2);
@@ -267,4 +268,4 @@ uint8_t* foleo_hmac_hkdf
     return out;
 }
 
-#endif
\ No newline at end of file
+#endif
index 6a6e3c6d6b758ff65031ce23befe42c6fb92b67f..3a405854d842641acb755ede5ae5f482274d8541 100644 (file)
@@ -298,7 +298,7 @@ uint8_t JBP_PRF_secret1[] =
 uint8_t JBP_PRF_seed1[] =
 {
     0xa0, 0xba, 0x9f, 0x93, 0x6c, 0xda, 0x31, 0x18,
-    0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c,
+    0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c
 };
 uint8_t JBP_PRF_label1[] =
 {
@@ -339,19 +339,12 @@ uint8_t RFC5869_HKDF_info1[] =
 };
 uint8_t RFC5869_HKDF_result1[] =
 {
-    0xe3, 0xf2, 0x29, 0xba, 0x72, 0x7b, 0xe1, 0x7b,
-    0x8d, 0x12, 0x26, 0x20, 0x55, 0x7c, 0xd4, 0x53,
-    0xc2, 0xaa, 0xb2, 0x1d, 0x07, 0xc3, 0xd4, 0x95,
-    0x32, 0x9b, 0x52, 0xd4, 0xe6, 0x1e, 0xdb, 0x5a,
-    0x6b, 0x30, 0x17, 0x91, 0xe9, 0x0d, 0x35, 0xc9,
-    0xc9, 0xa4, 0x6b, 0x4e, 0x14, 0xba, 0xf9, 0xaf,
-    0x0f, 0xa0, 0x22, 0xf7, 0x07, 0x7d, 0xef, 0x17,
-    0xab, 0xfd, 0x37, 0x97, 0xc0, 0x56, 0x4b, 0xab,
-    0x4f, 0xbc, 0x91, 0x66, 0x6e, 0x9d, 0xef, 0x9b,
-    0x97, 0xfc, 0xe3, 0x4f, 0x79, 0x67, 0x89, 0xba,
-    0xa4, 0x80, 0x82, 0xd1, 0x22, 0xee, 0x42, 0xc5,
-    0xa7, 0x2e, 0x5a, 0x51, 0x10, 0xff, 0xf7, 0x01,
-    0x87, 0x34, 0x7b, 0x66
+    0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
+    0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
+    0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
+    0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
+    0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
+    0x58, 0x65
 };
 uint8_t RFC5869_HKDF_ikm2[] =
 {
index 45765947a2107d0e5c04675486a09139eb0c863f..5ed6c8ffc486db0af7bef8c2a2f359ebb50ef5b3 100644 (file)
@@ -77,7 +77,7 @@ void main()
     test_hmac(2, 6, RFC4231_HMAC_key6, sizeof(RFC4231_HMAC_key6), RFC4231_HMAC_data6, sizeof(RFC4231_HMAC_data6), RFC4231_HMAC_result6, sizeof(RFC4231_HMAC_result6));
     test_hmac(2, 7, RFC4231_HMAC_key7, sizeof(RFC4231_HMAC_key7), RFC4231_HMAC_data7, sizeof(RFC4231_HMAC_data7), RFC4231_HMAC_result7, sizeof(RFC4231_HMAC_result7));
 
-    test_prf(1, JBP_PRF_secret1, sizeof(JBP_PRF_secret1), JBP_PRF_label1, sizeof(JBP_PRF_label1), JBP_PRF_seed1, sizeof(JBP_PRF_label1), JBP_PRF_result1, sizeof(JBP_PRF_result1));
+    test_prf(1, JBP_PRF_secret1, sizeof(JBP_PRF_secret1), JBP_PRF_label1, sizeof(JBP_PRF_label1), JBP_PRF_seed1, sizeof(JBP_PRF_seed1), JBP_PRF_result1, sizeof(JBP_PRF_result1));
 
     test_hkdf(1, RFC5869_HKDF_ikm1, sizeof(RFC5869_HKDF_ikm1), RFC5869_HKDF_salt1, sizeof(RFC5869_HKDF_salt1), RFC5869_HKDF_info1, sizeof(RFC5869_HKDF_info1), RFC5869_HKDF_result1, sizeof(RFC5869_HKDF_result1));
     test_hkdf(2, RFC5869_HKDF_ikm2, sizeof(RFC5869_HKDF_ikm2), RFC5869_HKDF_salt2, sizeof(RFC5869_HKDF_salt2), RFC5869_HKDF_info2, sizeof(RFC5869_HKDF_info2), RFC5869_HKDF_result2, sizeof(RFC5869_HKDF_result2));