mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-24 20:45:17 -07:00
scalarmult: add the exact test from the irtf-cfrg-curves draft
Use guarded memory by the way.
This commit is contained in:
parent
fe27e6c136
commit
6be1ce3f34
@ -2,30 +2,46 @@
|
||||
#define TEST_NAME "scalarmult"
|
||||
#include "cmptest.h"
|
||||
|
||||
unsigned char alicesk[32]
|
||||
const unsigned char alicesk[crypto_scalarmult_BYTES]
|
||||
= { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1,
|
||||
0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0,
|
||||
0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a };
|
||||
|
||||
unsigned char alicepk[32];
|
||||
const unsigned char bobsk[crypto_scalarmult_BYTES]
|
||||
= { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f,
|
||||
0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18,
|
||||
0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88, 0xe0, 0xeb };
|
||||
|
||||
char hex[crypto_scalarmult_BYTES * 2 + 1];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
unsigned char *alicepk = sodium_malloc(crypto_scalarmult_BYTES);
|
||||
unsigned char *bobpk = sodium_malloc(crypto_scalarmult_BYTES);
|
||||
unsigned char *k = sodium_malloc(crypto_scalarmult_BYTES);
|
||||
|
||||
assert(alicepk != NULL && bobpk != NULL && k != NULL);
|
||||
|
||||
crypto_scalarmult_base(alicepk, alicesk);
|
||||
sodium_bin2hex(hex, sizeof hex, alicepk, crypto_scalarmult_BYTES);
|
||||
printf("%s\n", hex);
|
||||
|
||||
crypto_scalarmult_base(bobpk, bobsk);
|
||||
sodium_bin2hex(hex, sizeof hex, bobpk, crypto_scalarmult_BYTES);
|
||||
printf("%s\n", hex);
|
||||
|
||||
crypto_scalarmult(k, alicesk, bobpk);
|
||||
sodium_bin2hex(hex, sizeof hex, k, crypto_scalarmult_BYTES);
|
||||
printf("%s\n", hex);
|
||||
|
||||
crypto_scalarmult(k, bobsk, alicepk);
|
||||
sodium_bin2hex(hex, sizeof hex, k, crypto_scalarmult_BYTES);
|
||||
printf("%s\n", hex);
|
||||
|
||||
sodium_free(k);
|
||||
sodium_free(bobpk);
|
||||
sodium_free(alicepk);
|
||||
|
||||
for (i = 0; i < 32; ++i) {
|
||||
if (i > 0) {
|
||||
printf(",");
|
||||
} else {
|
||||
printf(" ");
|
||||
}
|
||||
printf("0x%02x", (unsigned int)alicepk[i]);
|
||||
if (i % 8 == 7) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
assert(crypto_scalarmult_bytes() > 0U);
|
||||
assert(crypto_scalarmult_scalarbytes() > 0U);
|
||||
assert(strcmp(crypto_scalarmult_primitive(), "curve25519") == 0);
|
||||
|
@ -1,4 +1,4 @@
|
||||
0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54
|
||||
,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a
|
||||
,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4
|
||||
,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a
|
||||
8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a
|
||||
de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f
|
||||
4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742
|
||||
4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742
|
||||
|
Loading…
Reference in New Issue
Block a user