Loading crypto/ec/curve448/arch_32/f_impl.c +30 −37 Original line number Original line Diff line number Diff line Loading @@ -12,14 +12,6 @@ #include "field.h" #include "field.h" #if (defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) && !defined(I_HATE_UNROLLED_LOOPS)) \ || defined(C448_FORCE_UNROLL) # define REPEAT8(_x) _x _x _x _x _x _x _x _x # define FOR_LIMB(_i,_start,_end,_x) do { _i=_start; REPEAT8( if (_i<_end) { _x; } _i++;) } while (0) #else # define FOR_LIMB(_i,_start,_end,_x) do { for (_i=_start; _i<_end; _i++) _x; } while (0) #endif void gf_mul(gf_s * RESTRICT cs, const gf as, const gf bs) void gf_mul(gf_s * RESTRICT cs, const gf as, const gf bs) { { const uint32_t *a = as->limb, *b = bs->limb; const uint32_t *a = as->limb, *b = bs->limb; Loading @@ -34,30 +26,28 @@ void gf_mul(gf_s * RESTRICT cs, const gf as, const gf bs) bb[i] = b[i] + b[i + 8]; bb[i] = b[i] + b[i + 8]; } } FOR_LIMB(j, 0, 8, { for (j = 0; j < 8; j++) { accum2 = 0; accum2 = 0; FOR_LIMB(i, 0, j + 1, { for (i = 0; i < j + 1; i++) { accum2 += widemul(a[j - i], b[i]); accum2 += widemul(a[j - i], b[i]); accum1 += widemul(aa[j - i], bb[i]); accum1 += widemul(aa[j - i], bb[i]); accum0 += widemul(a[8 + j - i], b[8 + i]); accum0 += widemul(a[8 + j - i], b[8 + i]); } } ); accum1 -= accum2; accum0 += accum2; accum1 -= accum2; accum0 += accum2; accum2 = 0; accum2 = 0; FOR_LIMB(i, j + 1, 8, { for (i = j + 1; i < 8; i++) { accum0 -= accum0 -= widemul(a[8 + j - i], b[i]); widemul(a[8 + j - i], b[i]); accum2 += widemul(aa[8 + j - i], bb[i]); accum2 += widemul(aa[8 + j - i], bb[i]); accum1 += widemul(a[16 + j - i], b[8 + i]); accum1 += widemul(a[16 + j - i], b[8 + i]); } } ); accum1 += accum2; accum1 += accum2; accum0 += accum2; accum0 += accum2; c[j] = ((uint32_t)(accum0)) & mask; c[j] = ((uint32_t)(accum0)) & mask; c[j + 8] = ((uint32_t)(accum1)) & mask; c[j + 8] = ((uint32_t)(accum1)) & mask; accum0 >>= 28; accum1 >>= 28; accum0 >>= 28; }); accum1 >>= 28; } accum0 += accum1; accum0 += accum1; accum0 += c[8]; accum0 += c[8]; Loading @@ -81,11 +71,14 @@ void gf_mulw_unsigned(gf_s * RESTRICT cs, const gf as, uint32_t b) assert(b < 1 << 28); assert(b < 1 << 28); FOR_LIMB(i, 0, 8, { for (i = 0; i < 8; i++) { accum0 += widemul(b, a[i]); accum8 += widemul(b, a[i + 8]); accum0 += widemul(b, a[i]); c[i] = accum0 & mask; accum0 >>= 28; accum8 += widemul(b, a[i + 8]); c[i + 8] = accum8 & mask; accum8 >>= 28; c[i] = accum0 & mask; }); accum0 >>= 28; c[i + 8] = accum8 & mask; accum8 >>= 28; } accum0 += accum8 + c[8]; accum0 += accum8 + c[8]; c[8] = ((uint32_t)accum0) & mask; c[8] = ((uint32_t)accum0) & mask; Loading crypto/ec/curve448/f_generic.c +6 −4 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,7 @@ void gf_serialize(uint8_t serial[SER_BYTES], const gf x, int with_hibit) if (!with_hibit) if (!with_hibit) assert(gf_hibit(red) == 0); assert(gf_hibit(red) == 0); UNROLL for (i = 0; i < (with_hibit ? X_SER_BYTES : SER_BYTES); i++) { for (i = 0; i < (with_hibit ? X_SER_BYTES : SER_BYTES); i++) { if (fill < 8 && j < NLIMBS) { if (fill < 8 && j < NLIMBS) { buffer |= ((dword_t) red->limb[LIMBPERM(j)]) << fill; buffer |= ((dword_t) red->limb[LIMBPERM(j)]) << fill; fill += LIMB_PLACE_VALUE(LIMBPERM(j)); fill += LIMB_PLACE_VALUE(LIMBPERM(j)); Loading Loading @@ -73,9 +73,11 @@ mask_t gf_deserialize(gf x, const uint8_t serial[SER_BYTES], int with_hibit, unsigned int i; unsigned int i; mask_t succ; mask_t succ; UNROLL for (i = 0; i < NLIMBS; i++) { for (i = 0; i < NLIMBS; i++) { UNROLL while (fill < LIMB_PLACE_VALUE(LIMBPERM(i)) && j < nbytes) { while (fill < LIMB_PLACE_VALUE(LIMBPERM(i)) && j < nbytes) { uint8_t sj = serial[j]; uint8_t sj; sj = serial[j]; if (j == nbytes - 1) if (j == nbytes - 1) sj &= ~hi_nmask; sj &= ~hi_nmask; buffer |= ((dword_t) sj) << fill; buffer |= ((dword_t) sj) << fill; Loading crypto/ec/curve448/word.h +0 −12 Original line number Original line Diff line number Diff line Loading @@ -59,18 +59,6 @@ typedef int64_t dsword_t; # error "For now we only support 32- and 64-bit architectures." # error "For now we only support 32- and 64-bit architectures." # endif # endif /* PERF: vectorize vs unroll */ # ifdef __clang__ # if 100*__clang_major__ + __clang_minor__ > 305 # define UNROLL _Pragma("clang loop unroll(full)") # endif # endif # ifndef UNROLL # define UNROLL # endif /* /* * The plan on booleans: The external interface uses c448_bool_t, but this * The plan on booleans: The external interface uses c448_bool_t, but this * might be a different size than our particular arch's word_t (and thus * might be a different size than our particular arch's word_t (and thus Loading Loading
crypto/ec/curve448/arch_32/f_impl.c +30 −37 Original line number Original line Diff line number Diff line Loading @@ -12,14 +12,6 @@ #include "field.h" #include "field.h" #if (defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) && !defined(I_HATE_UNROLLED_LOOPS)) \ || defined(C448_FORCE_UNROLL) # define REPEAT8(_x) _x _x _x _x _x _x _x _x # define FOR_LIMB(_i,_start,_end,_x) do { _i=_start; REPEAT8( if (_i<_end) { _x; } _i++;) } while (0) #else # define FOR_LIMB(_i,_start,_end,_x) do { for (_i=_start; _i<_end; _i++) _x; } while (0) #endif void gf_mul(gf_s * RESTRICT cs, const gf as, const gf bs) void gf_mul(gf_s * RESTRICT cs, const gf as, const gf bs) { { const uint32_t *a = as->limb, *b = bs->limb; const uint32_t *a = as->limb, *b = bs->limb; Loading @@ -34,30 +26,28 @@ void gf_mul(gf_s * RESTRICT cs, const gf as, const gf bs) bb[i] = b[i] + b[i + 8]; bb[i] = b[i] + b[i + 8]; } } FOR_LIMB(j, 0, 8, { for (j = 0; j < 8; j++) { accum2 = 0; accum2 = 0; FOR_LIMB(i, 0, j + 1, { for (i = 0; i < j + 1; i++) { accum2 += widemul(a[j - i], b[i]); accum2 += widemul(a[j - i], b[i]); accum1 += widemul(aa[j - i], bb[i]); accum1 += widemul(aa[j - i], bb[i]); accum0 += widemul(a[8 + j - i], b[8 + i]); accum0 += widemul(a[8 + j - i], b[8 + i]); } } ); accum1 -= accum2; accum0 += accum2; accum1 -= accum2; accum0 += accum2; accum2 = 0; accum2 = 0; FOR_LIMB(i, j + 1, 8, { for (i = j + 1; i < 8; i++) { accum0 -= accum0 -= widemul(a[8 + j - i], b[i]); widemul(a[8 + j - i], b[i]); accum2 += widemul(aa[8 + j - i], bb[i]); accum2 += widemul(aa[8 + j - i], bb[i]); accum1 += widemul(a[16 + j - i], b[8 + i]); accum1 += widemul(a[16 + j - i], b[8 + i]); } } ); accum1 += accum2; accum1 += accum2; accum0 += accum2; accum0 += accum2; c[j] = ((uint32_t)(accum0)) & mask; c[j] = ((uint32_t)(accum0)) & mask; c[j + 8] = ((uint32_t)(accum1)) & mask; c[j + 8] = ((uint32_t)(accum1)) & mask; accum0 >>= 28; accum1 >>= 28; accum0 >>= 28; }); accum1 >>= 28; } accum0 += accum1; accum0 += accum1; accum0 += c[8]; accum0 += c[8]; Loading @@ -81,11 +71,14 @@ void gf_mulw_unsigned(gf_s * RESTRICT cs, const gf as, uint32_t b) assert(b < 1 << 28); assert(b < 1 << 28); FOR_LIMB(i, 0, 8, { for (i = 0; i < 8; i++) { accum0 += widemul(b, a[i]); accum8 += widemul(b, a[i + 8]); accum0 += widemul(b, a[i]); c[i] = accum0 & mask; accum0 >>= 28; accum8 += widemul(b, a[i + 8]); c[i + 8] = accum8 & mask; accum8 >>= 28; c[i] = accum0 & mask; }); accum0 >>= 28; c[i + 8] = accum8 & mask; accum8 >>= 28; } accum0 += accum8 + c[8]; accum0 += accum8 + c[8]; c[8] = ((uint32_t)accum0) & mask; c[8] = ((uint32_t)accum0) & mask; Loading
crypto/ec/curve448/f_generic.c +6 −4 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,7 @@ void gf_serialize(uint8_t serial[SER_BYTES], const gf x, int with_hibit) if (!with_hibit) if (!with_hibit) assert(gf_hibit(red) == 0); assert(gf_hibit(red) == 0); UNROLL for (i = 0; i < (with_hibit ? X_SER_BYTES : SER_BYTES); i++) { for (i = 0; i < (with_hibit ? X_SER_BYTES : SER_BYTES); i++) { if (fill < 8 && j < NLIMBS) { if (fill < 8 && j < NLIMBS) { buffer |= ((dword_t) red->limb[LIMBPERM(j)]) << fill; buffer |= ((dword_t) red->limb[LIMBPERM(j)]) << fill; fill += LIMB_PLACE_VALUE(LIMBPERM(j)); fill += LIMB_PLACE_VALUE(LIMBPERM(j)); Loading Loading @@ -73,9 +73,11 @@ mask_t gf_deserialize(gf x, const uint8_t serial[SER_BYTES], int with_hibit, unsigned int i; unsigned int i; mask_t succ; mask_t succ; UNROLL for (i = 0; i < NLIMBS; i++) { for (i = 0; i < NLIMBS; i++) { UNROLL while (fill < LIMB_PLACE_VALUE(LIMBPERM(i)) && j < nbytes) { while (fill < LIMB_PLACE_VALUE(LIMBPERM(i)) && j < nbytes) { uint8_t sj = serial[j]; uint8_t sj; sj = serial[j]; if (j == nbytes - 1) if (j == nbytes - 1) sj &= ~hi_nmask; sj &= ~hi_nmask; buffer |= ((dword_t) sj) << fill; buffer |= ((dword_t) sj) << fill; Loading
crypto/ec/curve448/word.h +0 −12 Original line number Original line Diff line number Diff line Loading @@ -59,18 +59,6 @@ typedef int64_t dsword_t; # error "For now we only support 32- and 64-bit architectures." # error "For now we only support 32- and 64-bit architectures." # endif # endif /* PERF: vectorize vs unroll */ # ifdef __clang__ # if 100*__clang_major__ + __clang_minor__ > 305 # define UNROLL _Pragma("clang loop unroll(full)") # endif # endif # ifndef UNROLL # define UNROLL # endif /* /* * The plan on booleans: The external interface uses c448_bool_t, but this * The plan on booleans: The external interface uses c448_bool_t, but this * might be a different size than our particular arch's word_t (and thus * might be a different size than our particular arch's word_t (and thus Loading