binary searching is finished!
[mkp224o.git] / test_ed25519.c
blob78c11bcae39b2e6493a24dfe8fe3956cd668bc72
1 #include <stddef.h>
2 #include <stdint.h>
3 #include <string.h>
4 #include <assert.h>
5 #include <stdio.h>
6 #include "types.h"
7 #include "base16.h"
8 #include "ed25519/ed25519.h"
10 struct pktest {
11 const char *seed;
12 const char *secret;
13 const char *public;
14 } test0[] = {
16 "26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36",
17 "c0a4de23cc64392d85aa1da82b3defddbea946d13bb053bf8489fa9296281f49"
18 "5022f1f7ec0dcf52f07d4c7965c4eaed121d5d88d0a8ff546b06116a20e97755",
19 "c2247870536a192d142d056abefca68d6193158e7c1a59c1654c954eccaff894",
22 "fba7a5366b5cb98c2667a18783f5cf8f4f8d1a2ce939ad22a6e685edde85128d",
23 "18a8a69a06790dac778e882f7e868baacfa12521a5c058f5194f3a729184514a"
24 "2a656fe7799c3e41f43d756da8d9cd47a061316cfe6147e23ea2f90d1ca45f30",
25 "1519a3b15816a1aafab0b213892026ebf5c0dc232c58b21088d88cb90e9b940d"
29 #define WARN(test) if (!(test)) \
30 fprintf(stderr, "check failed @ %d: %s\n", (int)__LINE__, #test)
32 #define WARNF(test) if (!(test) && (fprintf(stderr, "check failed @ %d: %s\n", (int)__LINE__, #test), 1))
34 #define SEEDBYTES 32
35 #define SECRETKEYBYTES 64
36 #define PUBLICKEYBYTES 32
38 int main()
40 u8 seedbuf[SEEDBYTES];
41 u8 secretbuf1[SECRETKEYBYTES];
42 u8 secretbuf2[SECRETKEYBYTES];
43 u8 publicbuf1[PUBLICKEYBYTES];
44 u8 publicbuf2[PUBLICKEYBYTES];
45 u8 mask;
46 char str1[1024], str2[1024];
47 for (size_t i = 0; i < sizeof(test0)/sizeof(test0[0]); ++i) {
48 base16_from(seedbuf, &mask, test0[i].seed);
49 base16_from(secretbuf1, &mask, test0[i].secret);
50 base16_from(publicbuf1, &mask, test0[i].public);
51 ed25519_seckey_expand(secretbuf2, seedbuf);
52 WARNF(memcmp(secretbuf1, secretbuf2, SECRETKEYBYTES) == 0) {
53 base16_to(str1, secretbuf1, sizeof(secretbuf1));
54 base16_to(str2, secretbuf2, sizeof(secretbuf2));
55 fprintf(stderr, "expected: %s got %s\n", str1, str2);
57 ed25519_pubkey(publicbuf2, secretbuf1);
58 WARNF(memcmp(publicbuf1, publicbuf2, PUBLICKEYBYTES) == 0) {
59 base16_to(str1, publicbuf1, sizeof(publicbuf1));
60 base16_to(str2, publicbuf2, sizeof(publicbuf2));
61 fprintf(stderr, "expected: %s got %s\n", str1, str2);
65 return 0;