Skip to content

Commit

Permalink
Merge branch 'update-PERK-m4'
Browse files Browse the repository at this point in the history
improve compression for PERK short levels I and II #328
  • Loading branch information
rpls committed Jan 20, 2024
2 parents ca8b4f3 + 4702ce9 commit 82f4e23
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 161 deletions.
8 changes: 4 additions & 4 deletions crypto_sign/perk-128-short-3/m4/bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ void bignum_add(const struct bn* a, const struct bn* b, struct bn* c)
require(b, "b is null");
require(c, "c is null");

DTYPE_TMP tmp;
int carry = 0;
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i)
{
DTYPE_TMP tmp;
tmp = (DTYPE_TMP)a->array[i] + b->array[i] + carry;
carry = (tmp > MAX_VAL);
c->array[i] = (tmp & MAX_VAL);
Expand All @@ -117,13 +117,13 @@ void bignum_sub(const struct bn* a, const struct bn* b, struct bn* c)
require(b, "b is null");
require(c, "c is null");

DTYPE_TMP res;
DTYPE_TMP tmp1;
DTYPE_TMP tmp2;
int borrow = 0;
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i)
{
DTYPE_TMP res;
DTYPE_TMP tmp1;
DTYPE_TMP tmp2;
tmp1 = (DTYPE_TMP)a->array[i] + (MAX_VAL + 1); /* + number_base */
tmp2 = (DTYPE_TMP)b->array[i] + borrow;
res = (tmp1 - tmp2);
Expand Down
19 changes: 15 additions & 4 deletions crypto_sign/perk-128-short-3/m4/bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ There may well be room for performance-optimizations and improvements.
*/

#include "parameters.h"

#include <stdint.h>
#include <assert.h>

Expand All @@ -30,10 +32,19 @@ There may well be room for performance-optimizations and improvements.
#endif

/* Size of big-numbers in bytes */
//#define BN_ARRAY_SIZE (64 / WORD_SIZE)
//#define BN_ARRAY_SIZE (128 / WORD_SIZE)
#define BN_ARRAY_SIZE 28 // PERK LEVEL 5 custom WORLD_SIZE

#if (PARAM_N1 == 79 || PARAM_N1 == 83)
#define BN_ARRAY_SIZE 13 // PERK LEVEL=1, T=3,5 custom WORLD_SIZE
#elif (PARAM_N1 == 112)
#define BN_ARRAY_SIZE 19 // PERK LEVEL=3, T=3 custom WORLD_SIZE
#elif (PARAM_N1 == 116)
#define BN_ARRAY_SIZE 20 // PERK LEVEL=3, T=5 custom WORLD_SIZE
#elif (PARAM_N1 == 146)
#define BN_ARRAY_SIZE 27 // PERK LEVEL=5, T=3 custom WORLD_SIZE
#elif (PARAM_N1 == 150)
#define BN_ARRAY_SIZE 28 // PERK LEVEL=5, T=5 custom WORLD_SIZE
#else
#error Invalid value for parameter PARAM_N1
#endif

/* Here comes the compile-time specialization for how large the underlying array size should be. */
/* The choices are 1, 2 and 4 bytes in size with uint32, uint64 for WORD_SIZE==4, as temporary. */
Expand Down
Loading

0 comments on commit 82f4e23

Please sign in to comment.