Browse Source

Move to separated directory. Get ready for p434

master
Henry Case 5 years ago
parent
commit
c18cbd517a
10 changed files with 16 additions and 16 deletions
  1. +0
    -0
      p503/arith.go
  2. +4
    -4
      p503/consts.go
  3. +3
    -3
      p503/curve.go
  4. +0
    -0
      p503/etc/PQCkemKAT_434.rsp
  5. +9
    -9
      p503/fp.go
  6. +0
    -0
      p503/go.mod
  7. +0
    -0
      p503/go.sum
  8. +0
    -0
      p503/sike.go
  9. +0
    -0
      p503/sike_test.go
  10. +0
    -0
      p503/types.go

arith.go → p503/arith.go View File


consts.go → p503/consts.go View File

@@ -14,25 +14,25 @@ var p503 = Fp{
}

// 2*503
var p503x2 = Fp{
var pX2 = Fp{
0xFFFFFFFFFFFFFFFE, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0x57FFFFFFFFFFFFFF,
0x2610B7B44423CF41, 0x3737ED90F6FCFB5E, 0xC08B8D7BB4EF49A0, 0x0080CDEA83023C3C,
}

// p503 + 1
var p503p1 = Fp{
var p1 = Fp{
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0xAC00000000000000,
0x13085BDA2211E7A0, 0x1B9BF6C87B7E7DAF, 0x6045C6BDDA77A4D0, 0x004066F541811E1E,
}

// R^2=(2^512)^2 mod p
var p503R2 = Fp{
var pR2 = Fp{
0x5289A0CF641D011F, 0x9B88257189FED2B9, 0xA3B365D58DC8F17A, 0x5BC57AB6EFF168EC,
0x9E51998BD84D4423, 0xBF8999CBAC3B5695, 0x46E9127BCE14CDB6, 0x003F6CFCE8B81771,
}

// p503 + 1 left-shifted by 8, assuming little endianness
var p503p1s8 = Fp{
var p1s8 = Fp{
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x085BDA2211E7A0AC, 0x9BF6C87B7E7DAF13, 0x45C6BDDA77A4D01B, 0x4066F541811E1E60,
}

curve.go → p503/curve.go View File

@@ -36,9 +36,9 @@ func toMontDomain(x *Fp2) {
var aRR FpX2

// convert to montgomery domain
fpMul(&aRR, &x.A, &p503R2) // = a*R*R
fpMontRdc(&x.A, &aRR) // = a*R mod p
fpMul(&aRR, &x.B, &p503R2)
fpMul(&aRR, &x.A, &pR2) // = a*R*R
fpMontRdc(&x.A, &aRR) // = a*R mod p
fpMul(&aRR, &x.B, &pR2)
fpMontRdc(&x.B, &aRR)
}


etc/PQCkemKAT_434.rsp → p503/etc/PQCkemKAT_434.rsp View File


fpP503.go → p503/fp.go View File

@@ -15,17 +15,17 @@ func fpAddRdc(z, x, y *Fp) {
z[i], carry = bits.Add64(x[i], y[i], carry)
}

// z = z - p503x2
// z = z - pX2
carry = 0
for i := 0; i < FP_WORDS; i++ {
z[i], carry = bits.Sub64(z[i], p503x2[i], carry)
z[i], carry = bits.Sub64(z[i], pX2[i], carry)
}

// if z<0 add p503x2 back
// if z<0 add pX2 back
mask := uint64(0 - carry)
carry = 0
for i := 0; i < FP_WORDS; i++ {
z[i], carry = bits.Add64(z[i], p503x2[i]&mask, carry)
z[i], carry = bits.Add64(z[i], pX2[i]&mask, carry)
}
}

@@ -33,16 +33,16 @@ func fpAddRdc(z, x, y *Fp) {
func fpSubRdc(z, x, y *Fp) {
var borrow uint64

// z = z - p503x2
// z = z - pX2
for i := 0; i < FP_WORDS; i++ {
z[i], borrow = bits.Sub64(x[i], y[i], borrow)
}

// if z<0 add p503x2 back
// if z<0 add pX2 back
mask := uint64(0 - borrow)
borrow = 0
for i := 0; i < FP_WORDS; i++ {
z[i], borrow = bits.Add64(z[i], p503x2[i]&mask, borrow)
z[i], borrow = bits.Add64(z[i], pX2[i]&mask, borrow)
}
}

@@ -116,7 +116,7 @@ func fpMontRdc(z *Fp, x *FpX2) {
for i := 0; i < FP_WORDS; i++ {
for j := 0; j < i; j++ {
if j < (i - count + 1) {
hi, lo = bits.Mul64(z[j], p503p1[i-j])
hi, lo = bits.Mul64(z[j], p1[i-j])
v, carry = bits.Add64(lo, v, 0)
u, carry = bits.Add64(hi, u, carry)
t += carry
@@ -138,7 +138,7 @@ func fpMontRdc(z *Fp, x *FpX2) {
}
for j := i - FP_WORDS + 1; j < FP_WORDS; j++ {
if j < (FP_WORDS - count) {
hi, lo = bits.Mul64(z[j], p503p1[i-j])
hi, lo = bits.Mul64(z[j], p1[i-j])
v, carry = bits.Add64(lo, v, 0)
u, carry = bits.Add64(hi, u, carry)
t += carry

go.mod → p503/go.mod View File


go.sum → p503/go.sum View File


sike.go → p503/sike.go View File


sike_test.go → p503/sike_test.go View File


types.go → p503/types.go View File


Loading…
Cancel
Save