mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-25 22:11:08 +00:00
Add tests for the carry operation in sha384 and sha512, which support
message of up to 2^128 bytes and therefore must use a high / low pair.
This commit is contained in:
parent
910c782b2f
commit
c9536ec04b
2 changed files with 78 additions and 2 deletions
39
t/t_sha384.c
39
t/t_sha384.c
|
@ -48,7 +48,11 @@
|
|||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
|
||||
#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
|
||||
#define sha384_ctx SHA512_CTX /* yes, 512 is correct */
|
||||
#define sha384_init(c) SHA384_Init(c)
|
||||
#define sha384_update(c, m, l) SHA384_Update(c, m, l)
|
||||
#define sha384_final(c, d) SHA384_Final(d, c)
|
||||
|
||||
static void
|
||||
t_sha384_complete(const void *msg, size_t msglen, uint8_t *digest)
|
||||
|
@ -228,6 +232,38 @@ t_sha384_perf(char **desc, void *arg)
|
|||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test the carry operation on the byte counter.
|
||||
*/
|
||||
static int
|
||||
t_sha384_carry(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
|
||||
{
|
||||
sha384_ctx ctx;
|
||||
uint8_t digest[SHA384_DIGEST_LEN];
|
||||
static uint8_t expect[SHA384_DIGEST_LEN] = {
|
||||
0x04, 0xa8, 0xab, 0x2a, 0x7d, 0xe6, 0x68, 0x22,
|
||||
0xcd, 0x45, 0xfd, 0xc5, 0x41, 0x62, 0x32, 0xca,
|
||||
0x6c, 0x59, 0x92, 0x41, 0x77, 0x99, 0xca, 0xa7,
|
||||
0xe2, 0xf0, 0x28, 0x77, 0x2b, 0x33, 0xbe, 0xa0,
|
||||
0xbe, 0xee, 0x4d, 0xd1, 0x9e, 0x18, 0xc4, 0x5f,
|
||||
0x47, 0x91, 0xb3, 0xd1, 0x9c, 0x3a, 0x81, 0xfb,
|
||||
};
|
||||
|
||||
sha384_init(&ctx);
|
||||
#if WITH_OPENSSL
|
||||
/* openssl counts bits */
|
||||
ctx.Nl = 0xffffffffffffff80LLU << 3LLU;
|
||||
ctx.Nh = 0xffffffffffffff80LLU >> 61LLU;
|
||||
#else
|
||||
/* cryb counts bytes and multiplies at the end */
|
||||
ctx.total[0] = 0xffffffffffffff80LLU;
|
||||
#endif
|
||||
sha384_update(&ctx, t_seq8, 256);
|
||||
sha384_final(&ctx, digest);
|
||||
return (t_compare_mem(expect, digest, SHA384_DIGEST_LEN));
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Boilerplate
|
||||
|
@ -267,6 +303,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha384_perf, &million,
|
||||
"performance test (1,000,000 bytes)");
|
||||
}
|
||||
t_add_test(t_sha384_carry, NULL, "byte counter carry");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
41
t/t_sha512.c
41
t/t_sha512.c
|
@ -48,7 +48,11 @@
|
|||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
|
||||
#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
|
||||
#define sha512_ctx SHA512_CTX
|
||||
#define sha512_init(c) SHA512_Init(c)
|
||||
#define sha512_update(c, m, l) SHA512_Update(c, m, l)
|
||||
#define sha512_final(c, d) SHA512_Final(d, c)
|
||||
|
||||
static void
|
||||
t_sha512_complete(const void *msg, size_t msglen, uint8_t *digest)
|
||||
|
@ -238,6 +242,40 @@ t_sha512_perf(char **desc, void *arg)
|
|||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test the carry operation on the byte counter.
|
||||
*/
|
||||
static int
|
||||
t_sha512_carry(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
|
||||
{
|
||||
sha512_ctx ctx;
|
||||
uint8_t digest[SHA512_DIGEST_LEN];
|
||||
static uint8_t expect[SHA512_DIGEST_LEN] = {
|
||||
0xbd, 0x25, 0x6d, 0xa8, 0xbf, 0xe0, 0x6c, 0xf0,
|
||||
0xc1, 0x8c, 0xe9, 0x58, 0xb8, 0xce, 0x43, 0xc7,
|
||||
0x9a, 0x3d, 0xec, 0x10, 0x58, 0x55, 0x00, 0x7f,
|
||||
0xe7, 0x75, 0x48, 0x66, 0xb2, 0x18, 0xc3, 0x98,
|
||||
0x91, 0x11, 0x75, 0x88, 0x53, 0x3e, 0xb3, 0x4b,
|
||||
0x83, 0x93, 0xca, 0x18, 0x8a, 0xbe, 0x32, 0x7d,
|
||||
0x4a, 0x54, 0x16, 0xbb, 0xdf, 0x9e, 0x9c, 0x3a,
|
||||
0xd7, 0x22, 0xc8, 0x0d, 0x71, 0x0f, 0x76, 0xc0,
|
||||
};
|
||||
|
||||
sha512_init(&ctx);
|
||||
#if WITH_OPENSSL
|
||||
/* openssl counts bits */
|
||||
ctx.Nl = 0xffffffffffffff80LLU << 3LLU;
|
||||
ctx.Nh = 0xffffffffffffff80LLU >> 61LLU;
|
||||
#else
|
||||
/* cryb counts bytes and multiplies at the end */
|
||||
ctx.total[0] = 0xffffffffffffff80LLU;
|
||||
#endif
|
||||
sha512_update(&ctx, t_seq8, 256);
|
||||
sha512_final(&ctx, digest);
|
||||
return (t_compare_mem(expect, digest, SHA512_DIGEST_LEN));
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Boilerplate
|
||||
|
@ -277,6 +315,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha512_perf, &million,
|
||||
"performance test (1,000,000 bytes)");
|
||||
}
|
||||
t_add_test(t_sha512_carry, NULL, "byte counter carry");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue