xref: /freebsd/sys/contrib/libsodium/test/default/scalarmult6.c (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
1 
2 #define TEST_NAME "scalarmult6"
3 #include "cmptest.h"
4 
5 static unsigned char bobsk_[crypto_scalarmult_SCALARBYTES] = {
6     0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f,
7     0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18,
8     0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88, 0xe0, 0xeb
9 };
10 
11 static unsigned char alicepk_[crypto_scalarmult_SCALARBYTES] = {
12     0x85, 0x20, 0xf0, 0x09, 0x89, 0x30, 0xa7, 0x54, 0x74, 0x8b, 0x7d,
13     0xdc, 0xb4, 0x3e, 0xf7, 0x5a, 0x0d, 0xbf, 0x3a, 0x0d, 0x26, 0x38,
14     0x1a, 0xf4, 0xeb, 0xa4, 0xa9, 0x8e, 0xaa, 0x9b, 0x4e, 0x6a
15 };
16 
17 int
18 main(void)
19 {
20     unsigned char *k;
21     unsigned char *bobsk;
22     unsigned char *alicepk;
23     int            i;
24     int            ret;
25 
26     k       = (unsigned char *) sodium_malloc(crypto_scalarmult_BYTES);
27     bobsk   = (unsigned char *) sodium_malloc(crypto_scalarmult_SCALARBYTES);
28     alicepk = (unsigned char *) sodium_malloc(crypto_scalarmult_SCALARBYTES);
29     assert(k != NULL && bobsk != NULL && alicepk != NULL);
30 
31     memcpy(bobsk, bobsk_, crypto_scalarmult_SCALARBYTES);
32     memcpy(alicepk, alicepk_, crypto_scalarmult_SCALARBYTES);
33 
34     ret = crypto_scalarmult(k, bobsk, alicepk);
35     assert(ret == 0);
36 
37     sodium_free(alicepk);
38     sodium_free(bobsk);
39 
40     for (i = 0; i < 32; ++i) {
41         if (i > 0) {
42             printf(",");
43         } else {
44             printf(" ");
45         }
46         printf("0x%02x", (unsigned int) k[i]);
47         if (i % 8 == 7) {
48             printf("\n");
49         }
50     }
51     sodium_free(k);
52 
53     return 0;
54 }
55