1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots.
package p434
import (
. "github.com/cloudflare/circl/dh/sidh/internal/common"
)
// -----------------------------------------------------------------------------
// Functions for traversing isogeny trees acoording to strategy. Key type 'A' is
//
// Traverses isogeny tree in order to compute xR, xP, xQ and xQmP needed
// for public key generation.
func traverseTreePublicKeyA(curve *ProjectiveCurveParameters, xR, phiP, phiQ, phiR *ProjectivePoint) {
var points = make([]ProjectivePoint, 0, 8)
var indices = make([]int, 0, 8)
var i, sIdx int
var phi isogeny4
cparam := CalcCurveParamsEquiv4(curve)
strat := params.A.IsogenyStrategy
stratSz := len(strat)
for j := 1; j <= stratSz; j++ {
for i <= stratSz-j {
points = append(points, *xR)
indices = append(indices, i)
k := strat[sIdx]
sIdx++
Pow2k(xR, &cparam, 2*k)
i += int(k)
}
cparam = phi.GenerateCurve(xR)
for k := 0; k < len(points); k++ {
points[k] = phi.EvaluatePoint(&points[k])
}
*phiP = phi.EvaluatePoint(phiP)
*phiQ = phi.EvaluatePoint(phiQ)
*phiR = phi.EvaluatePoint(phiR)
// pop xR from points
*xR, points = points[len(points)-1], points[:len(points)-1]
i, indices = int(indices[len(indices)-1]), indices[:len(indices)-1]
}
}
// Traverses isogeny tree in order to compute xR needed
// for public key generation.
func traverseTreeSharedKeyA(curve *ProjectiveCurveParameters, xR *ProjectivePoint) {
var points = make([]ProjectivePoint, 0, 8)
var indices = make([]int, 0, 8)
var i, sIdx int
var phi isogeny4
cparam := CalcCurveParamsEquiv4(curve)
strat := params.A.IsogenyStrategy
stratSz := len(strat)
for j := 1; j <= stratSz; j++ {
for i <= stratSz-j {
points = append(points, *xR)
indices = append(indices, i)
k := strat[sIdx]
sIdx++
Pow2k(xR, &cparam, 2*k)
i += int(k)
}
cparam = phi.GenerateCurve(xR)
for k := 0; k < len(points); k++ {
points[k] = phi.EvaluatePoint(&points[k])
}
// pop xR from points
*xR, points = points[len(points)-1], points[:len(points)-1]
i, indices = int(indices[len(indices)-1]), indices[:len(indices)-1]
}
}
// Traverses isogeny tree in order to compute xR, xP, xQ and xQmP needed
// for public key generation.
func traverseTreePublicKeyB(curve *ProjectiveCurveParameters, xR, phiP, phiQ, phiR *ProjectivePoint) {
var points = make([]ProjectivePoint, 0, 8)
var indices = make([]int, 0, 8)
var i, sIdx int
var phi isogeny3
cparam := CalcCurveParamsEquiv3(curve)
strat := params.B.IsogenyStrategy
stratSz := len(strat)
for j := 1; j <= stratSz; j++ {
for i <= stratSz-j {
points = append(points, *xR)
indices = append(indices, i)
k := strat[sIdx]
sIdx++
Pow3k(xR, &cparam, k)
i += int(k)
}
cparam = phi.GenerateCurve(xR)
for k := 0; k < len(points); k++ {
points[k] = phi.EvaluatePoint(&points[k])
}
*phiP = phi.EvaluatePoint(phiP)
*phiQ = phi.EvaluatePoint(phiQ)
*phiR = phi.EvaluatePoint(phiR)
// pop xR from points
*xR, points = points[len(points)-1], points[:len(points)-1]
i, indices = int(indices[len(indices)-1]), indices[:len(indices)-1]
}
}
// Traverses isogeny tree in order to compute xR, xP, xQ and xQmP needed
// for public key generation.
func traverseTreeSharedKeyB(curve *ProjectiveCurveParameters, xR *ProjectivePoint) {
var points = make([]ProjectivePoint, 0, 8)
var indices = make([]int, 0, 8)
var i, sIdx int
var phi isogeny3
cparam := CalcCurveParamsEquiv3(curve)
strat := params.B.IsogenyStrategy
stratSz := len(strat)
for j := 1; j <= stratSz; j++ {
for i <= stratSz-j {
points = append(points, *xR)
indices = append(indices, i)
k := strat[sIdx]
sIdx++
Pow3k(xR, &cparam, k)
i += int(k)
}
cparam = phi.GenerateCurve(xR)
for k := 0; k < len(points); k++ {
points[k] = phi.EvaluatePoint(&points[k])
}
// pop xR from points
*xR, points = points[len(points)-1], points[:len(points)-1]
i, indices = int(indices[len(indices)-1]), indices[:len(indices)-1]
}
}
// Generate a public key in the 2-torsion group. Public key is a set
// of three x-coordinates: xP,xQ,x(P-Q), where P,Q are points on E_a(Fp2)
func PublicKeyGenA(pub3Pt *[3]Fp2, prvBytes []byte) {
var xPA, xQA, xRA ProjectivePoint
var xPB, xQB, xRB, xR ProjectivePoint
var invZP, invZQ, invZR Fp2
var phi isogeny4
// Load points for A
xPA = ProjectivePoint{X: params.A.AffineP, Z: params.OneFp2}
xQA = ProjectivePoint{X: params.A.AffineQ, Z: params.OneFp2}
xRA = ProjectivePoint{X: params.A.AffineR, Z: params.OneFp2}
// Load points for B
xRB = ProjectivePoint{X: params.B.AffineR, Z: params.OneFp2}
xQB = ProjectivePoint{X: params.B.AffineQ, Z: params.OneFp2}
xPB = ProjectivePoint{X: params.B.AffineP, Z: params.OneFp2}
// Find isogeny kernel
xR = ScalarMul3Pt(¶ms.InitCurve, &xPA, &xQA, &xRA, params.A.SecretBitLen, prvBytes)
traverseTreePublicKeyA(¶ms.InitCurve, &xR, &xPB, &xQB, &xRB)
// Secret isogeny
phi.GenerateCurve(&xR)
xPA = phi.EvaluatePoint(&xPB)
xQA = phi.EvaluatePoint(&xQB)
xRA = phi.EvaluatePoint(&xRB)
Fp2Batch3Inv(&xPA.Z, &xQA.Z, &xRA.Z, &invZP, &invZQ, &invZR)
mul(&pub3Pt[0], &xPA.X, &invZP)
mul(&pub3Pt[1], &xQA.X, &invZQ)
mul(&pub3Pt[2], &xRA.X, &invZR)
}
// Generate a public key in the 2-torsion group. Public key is a set
// of three x-coordinates: xP,xQ,x(P-Q), where P,Q are points on E_a(Fp2)
func PublicKeyGenB(pub3Pt *[3]Fp2, prvBytes []byte) {
var xPB, xQB, xRB, xR ProjectivePoint
var xPA, xQA, xRA ProjectivePoint
var invZP, invZQ, invZR Fp2
var phi isogeny3
// Load points for B
xRB = ProjectivePoint{X: params.B.AffineR, Z: params.OneFp2}
xQB = ProjectivePoint{X: params.B.AffineQ, Z: params.OneFp2}
xPB = ProjectivePoint{X: params.B.AffineP, Z: params.OneFp2}
// Load points for A
xPA = ProjectivePoint{X: params.A.AffineP, Z: params.OneFp2}
xQA = ProjectivePoint{X: params.A.AffineQ, Z: params.OneFp2}
xRA = ProjectivePoint{X: params.A.AffineR, Z: params.OneFp2}
// Find isogeny kernel
xR = ScalarMul3Pt(¶ms.InitCurve, &xPB, &xQB, &xRB, params.B.SecretBitLen, prvBytes)
traverseTreePublicKeyB(¶ms.InitCurve, &xR, &xPA, &xQA, &xRA)
phi.GenerateCurve(&xR)
xPB = phi.EvaluatePoint(&xPA)
xQB = phi.EvaluatePoint(&xQA)
xRB = phi.EvaluatePoint(&xRA)
Fp2Batch3Inv(&xPB.Z, &xQB.Z, &xRB.Z, &invZP, &invZQ, &invZR)
mul(&pub3Pt[0], &xPB.X, &invZP)
mul(&pub3Pt[1], &xQB.X, &invZQ)
mul(&pub3Pt[2], &xRB.X, &invZR)
}
// -----------------------------------------------------------------------------
// Key agreement functions
//
// Establishing shared keys in in 2-torsion group
func DeriveSecretA(ss, prv []byte, pub3Pt *[3]Fp2) {
var xP, xQ, xQmP ProjectivePoint
var xR ProjectivePoint
var phi isogeny4
var jInv Fp2
// Recover curve coefficients
cparam := params.InitCurve
RecoverCoordinateA(&cparam, &pub3Pt[0], &pub3Pt[1], &pub3Pt[2])
// Find kernel of the morphism
xP = ProjectivePoint{X: pub3Pt[0], Z: params.OneFp2}
xQ = ProjectivePoint{X: pub3Pt[1], Z: params.OneFp2}
xQmP = ProjectivePoint{X: pub3Pt[2], Z: params.OneFp2}
xR = ScalarMul3Pt(&cparam, &xP, &xQ, &xQmP, params.A.SecretBitLen, prv)
// Traverse isogeny tree
traverseTreeSharedKeyA(&cparam, &xR)
// Calculate j-invariant on isogeneus curve
c := phi.GenerateCurve(&xR)
RecoverCurveCoefficients4(&cparam, &c)
Jinvariant(&cparam, &jInv)
FromMontgomery(&jInv, &jInv)
Fp2ToBytes(ss, &jInv, params.Bytelen)
}
// Establishing shared keys in in 3-torsion group
func DeriveSecretB(ss, prv []byte, pub3Pt *[3]Fp2) {
var xP, xQ, xQmP ProjectivePoint
var xR ProjectivePoint
var phi isogeny3
var jInv Fp2
// Recover curve coefficients
cparam := params.InitCurve
RecoverCoordinateA(&cparam, &pub3Pt[0], &pub3Pt[1], &pub3Pt[2])
// Find kernel of the morphism
xP = ProjectivePoint{X: pub3Pt[0], Z: params.OneFp2}
xQ = ProjectivePoint{X: pub3Pt[1], Z: params.OneFp2}
xQmP = ProjectivePoint{X: pub3Pt[2], Z: params.OneFp2}
xR = ScalarMul3Pt(&cparam, &xP, &xQ, &xQmP, params.B.SecretBitLen, prv)
// Traverse isogeny tree
traverseTreeSharedKeyB(&cparam, &xR)
// Calculate j-invariant on isogeneus curve
c := phi.GenerateCurve(&xR)
RecoverCurveCoefficients3(&cparam, &c)
Jinvariant(&cparam, &jInv)
FromMontgomery(&jInv, &jInv)
Fp2ToBytes(ss, &jInv, params.Bytelen)
}
|