pub/{ed25519,x25519,x448}.c: Use symbolic constants for sizes of things.
[catacomb] / pub / ed25519.c
index a5fe57b..655b1e6 100644 (file)
@@ -86,35 +86,35 @@ const key_fetchdef ed25519_privfetch[] = {
 
 #if F25519_IMPL == 26
 # define P p26
-  static const int32 bx_pieces[] = {
+  static const f25519_piece bx_pieces[] = {
     -14297830,  -7645148,  16144683, -16471763,  27570974,
      -2696100, -26142465,   8378389,  20764389,   8758491
   }, by_pieces[] = {
-    -26843560,  -6710886,  13421773, -13421773,  26843546,
-      6710886, -13421773,  13421773, -26843546,  26843546
+    -26843541,  -6710886,  13421773, -13421773,  26843546,
+      6710886, -13421773,  13421773, -26843546,  -6710886
   }, d_pieces[] = {
-    -10913629,  13857413, -15372611,   6949391,    114729,
-     -8787816,  -6275908,  -3247719, -18696448,  21499316
+    -10913610,  13857413, -15372611,   6949391,    114729,
+     -8787816,  -6275908,  -3247719, -18696448, -12055116
   };
 #endif
 #if F25519_IMPL == 10
 # define P p10
-  static const int16 bx_pieces[] = {
+  static const f25519_piece bx_pieces[] = {
      282,  373,  242,  386, -467,   86, -423,  318, -437,
       75,  236, -308,  421,   92,  439,  -35,  400,  452,
       82,  -40,  160,  441,  -51,  437, -365,  134
   }, by_pieces[] = {
-    -424,  410, -410,  410, -410, -102,  205, -205,  205,
+    -405,  410, -410,  410, -410, -102,  205, -205,  205,
     -205,  205, -410,  410, -410,  410,  102, -205,  205,
-    -205,  205, -205,  410, -410,  410, -410,  410
+    -205,  205, -205,  410, -410,  410, -410, -102
   }, d_pieces[] = {
-     163, -418,  310, -216, -178, -133,  367, -315, -380,
+     182, -418,  310, -216, -178, -133,  367, -315, -380,
     -351, -182, -255,    2,  152, -390, -136,  -52, -383,
-    -412, -398,  -12,  448, -469, -196,   55,  328
+    -412, -398,  -12,  448, -469, -196,   55, -184
   };
 #endif
 
-static const scaf_piece bz_pieces[NPIECE] = { 1, 0, /* ... */ };
+static const f25519_piece bz_pieces[NPIECE] = { 1, 0, /* ... */ };
 #define BX ((const f25519 *)bx_pieces)
 #define BY ((const f25519 *)by_pieces)
 #define BZ ((const f25519 *)bz_pieces)
@@ -512,11 +512,11 @@ static int vrf_pubkey(dstr dv[])
   dstr dpub = DSTR_INIT;
   int ok = 1;
 
-  if (dv[1].len != 32) die(1, "bad pub length");
+  if (dv[1].len != ED25519_PUBSZ) die(1, "bad pub length");
 
-  dstr_ensure(&dpub, 32); dpub.len = 32;
+  dstr_ensure(&dpub, ED25519_PUBSZ); dpub.len = ED25519_PUBSZ;
   ed25519_pubkey((octet *)dpub.buf, dv[0].buf, dv[0].len);
-  if (memcmp(dpub.buf, dv[1].buf, 64) != 0) {
+  if (memcmp(dpub.buf, dv[1].buf, ED25519_PUBSZ) != 0) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\tpriv = "); type_hex.dump(&dv[0], stderr);
@@ -535,13 +535,13 @@ static int vrf_sign(dstr dv[])
   dstr dsig = DSTR_INIT;
   int ok = 1;
 
-  if (dv[2].len != 64) die(1, "bad result length");
+  if (dv[2].len != ED25519_SIGSZ) die(1, "bad result length");
 
-  dstr_ensure(&dsig, 64); dsig.len = 64;
+  dstr_ensure(&dsig, ED25519_SIGSZ); dsig.len = ED25519_SIGSZ;
   ed25519_pubkey(K, dv[0].buf, dv[0].len);
   ed25519_sign((octet *)dsig.buf, dv[0].buf, dv[0].len, K,
               dv[1].buf, dv[1].len);
-  if (memcmp(dsig.buf, dv[2].buf, 64) != 0) {
+  if (memcmp(dsig.buf, dv[2].buf, ED25519_SIGSZ) != 0) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\tpriv = "); type_hex.dump(&dv[0], stderr);
@@ -560,8 +560,8 @@ static int vrf_verify(dstr dv[])
   int rc_want, rc_calc;
   int ok = 1;
 
-  if (dv[0].len != 32) die(1, "bad pub length");
-  if (dv[2].len != 64) die(1, "bad sig length");
+  if (dv[0].len != ED25519_PUBSZ) die(1, "bad pub length");
+  if (dv[2].len != ED25519_SIGSZ) die(1, "bad sig length");
   rc_want = *(int *)dv[3].buf;
 
   rc_calc = ed25519_verify((const octet *)dv[0].buf,