Debian Codegraph @

test/test_pub_derivation.c

raw symbols SCIP
1 #cxx . . $ `<file>/test/test_pub_derivation.c`/include <stdbool.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include <sodium.h>
6 #include <xeddsa.h>cxx . . $ `<file>/include/xeddsa.h`/
7
8 #include <test.h>cxx . . $ `<file>/test/test.h`/
9
10 #define NUM_KEY_PAIRScxx . . $ `test/test_pub_derivation.c:10:9`! 8192
11
12 int test_pub_derivationcxx . . $ test_pub_derivation(d1b40a211a1a4e4c).() {
13 uint8_tcxx . . $ uint8_t# priv[32], curve_pub_original[32], curve_pub_derived[32];
14 uint8_tcxx . . $ uint8_t# seed[32], ed_pub_original[32], ed_pub_derived[32];
15
16 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! failed = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
17
18 // Test on a set of different key pairs
19 for (uint32_tcxx . . $ uint32_t# i = 0; i < NUM_KEY_PAIRScxx . . $ `test/test_pub_derivation.c:10:9`!; i++) {
20 // Generate a Curve25519 key pair
21 randombytes_bufcxx . . $ randombytes_buf(5500c4293b1bbef0).(priv, 32);
22 priv_to_curve25519_pubcxx . . $ priv_to_curve25519_pub(225f8250db12d4ac).(curve_pub_original, priv);
23
24 // Derive the Curve25519 public key from the private key
25 priv_to_curve25519_pubcxx . . $ priv_to_curve25519_pub(225f8250db12d4ac).(curve_pub_derived, priv);
26
27 // Check whether the derived Curve25519 public key matches the original
28 if (memcmpcxx . . $ memcmp(36f949851efa3055).(curve_pub_original, curve_pub_derived, 32) != 0) {
29 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Derived Curve25519 public key does not match the original.\n");
30 failed = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
31 }
32
33 // Generate an Ed25519 key pair (seed + pub)
34 randombytes_bufcxx . . $ randombytes_buf(5500c4293b1bbef0).(seed, 32);
35 seed_to_ed25519_pubcxx . . $ seed_to_ed25519_pub(225f8250db12d4ac).(ed_pub_original, seed);
36
37 // Derive the Ed25519 public key from the seed (also tests private key from seed derivation)
38 seed_to_ed25519_pubcxx . . $ seed_to_ed25519_pub(225f8250db12d4ac).(ed_pub_derived, seed);
39
40 // Check whether the derived Ed25519 public key matches the original
41 if (memcmpcxx . . $ memcmp(36f949851efa3055).(ed_pub_original, ed_pub_derived, 32) != 0) {
42 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Derived Ed25519 public key does not match the original.\n");
43 failed = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
44 }
45 }
46
47 return failed ? -1 : 0;
48 }