Module: kamailio
Branch: master
Commit: 805b921c0d6958db1620b0712450ef7a128cb5ce
URL:
https://github.com/kamailio/kamailio/commit/805b921c0d6958db1620b0712450ef7…
Author: S-P Chan <shihping.chan(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-07-11T14:42:21+02:00
core: crypto add support for SHA-512/256 for RFCs 8760/7616
---
Modified: src/core/crypto/sha256.c
Modified: src/core/crypto/sha256.h
---
Diff:
https://github.com/kamailio/kamailio/commit/805b921c0d6958db1620b0712450ef7…
Patch:
https://github.com/kamailio/kamailio/commit/805b921c0d6958db1620b0712450ef7…
---
diff --git a/src/core/crypto/sha256.c b/src/core/crypto/sha256.c
index d27fd016251..ba5562755d6 100644
--- a/src/core/crypto/sha256.c
+++ b/src/core/crypto/sha256.c
@@ -301,6 +301,18 @@ const static sha2_word64 sha512_initial_hash_value[8] = {
0x5be0cd19137e2179ULL
};
+/* Initial hash value H for SHA-512/256 */
+const static sha2_word64 sha512_256_initial_hash_value[8] = {
+ 0x22312194FC2BF72CULL,
+ 0x9F555FA3C84C64C2ULL,
+ 0x2393B86B6F53B151ULL,
+ 0x963877195940EABDULL,
+ 0x96283EE2A88EFFE3ULL,
+ 0xBE5E1E2553863992ULL,
+ 0x2B0199FC2C85B8AAULL,
+ 0x0EB72DDC81C52CA2ULL
+};
+
/*
* Constant used by SHA256/384/512_End() functions for converting the
* digest to a readable hexadecimal character string:
@@ -636,7 +648,7 @@ char* sr_SHA256_Data(const sha2_byte* data, size_t len, char
digest[SHA256_DIGES
}
-/*** SHA-512: *********************************************************/
+/*** SHA-512 SHA-512/256: *********************************************************/
void sr_SHA512_Init(SHA512_CTX* context) {
if (context == (SHA512_CTX*)0) {
return;
@@ -646,6 +658,15 @@ void sr_SHA512_Init(SHA512_CTX* context) {
context->bitcount[0] = context->bitcount[1] = 0;
}
+void sr_SHA512_256_Init(SHA512_CTX* context) {
+ if (context == (SHA512_CTX*)0) {
+ return;
+ }
+ MEMCPY_BCOPY(context->state, sha512_256_initial_hash_value, SHA512_DIGEST_LENGTH);
+ MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH);
+ context->bitcount[0] = context->bitcount[1] = 0;
+}
+
#ifdef SHA2_UNROLL_TRANSFORM
/* Unrolled SHA-512 round macros: */
diff --git a/src/core/crypto/sha256.h b/src/core/crypto/sha256.h
index e93bdad855a..5710ed81a96 100644
--- a/src/core/crypto/sha256.h
+++ b/src/core/crypto/sha256.h
@@ -97,6 +97,7 @@ char* sr_SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
char* sr_SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
void sr_SHA512_Init(SHA512_CTX*);
+void sr_SHA512_256_Init(SHA512_CTX*);
void sr_SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
void sr_SHA512_Final(sha2_byte[SHA512_DIGEST_LENGTH], SHA512_CTX*);
char* sr_SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
@@ -117,6 +118,7 @@ char* sr_SHA384_End();
char* sr_SHA384_Data();
void sr_SHA512_Init();
+void sr_SHA512_256_Init();
void sr_SHA512_Update();
void sr_SHA512_Final();
char* sr_SHA512_End();