You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

334 line
17 KiB

  1. package cln16sidh
  2. import (
  3. "testing"
  4. )
  5. // Perform Alice's (2-isogeny) key generation, using the slow but simple multiplication-based strategy.
  6. //
  7. // This function just exists to ensure that the fast isogeny-tree strategy works correctly.
  8. func aliceKeyGenSlow(secretKey *SIDHSecretKeyAlice) SIDHPublicKeyAlice {
  9. var xP, xQ, xQmP, xR, xS ProjectivePoint
  10. xP.fromAffinePrimeField(&affine_xPB) // = ( x_P : 1) = x(P_B)
  11. xQ.fromAffinePrimeField(&affine_xPB) //
  12. xQ.x.Neg(&xQ.x) // = (-x_P : 1) = x(Q_B)
  13. xQmP = DistortAndDifference(&affine_xPB) // = x(Q_B - P_B)
  14. xR = SecretPoint(&affine_xPA, &affine_yPA, secretKey.scalar)
  15. var currentCurve ProjectiveCurveParameters
  16. // Starting curve has a = 0, so (A:C) = (0,1)
  17. currentCurve.A.Zero()
  18. currentCurve.C.One()
  19. var firstPhi FirstFourIsogeny
  20. currentCurve, firstPhi = ComputeFirstFourIsogeny(&currentCurve)
  21. xP = firstPhi.Eval(&xP)
  22. xQ = firstPhi.Eval(&xQ)
  23. xQmP = firstPhi.Eval(&xQmP)
  24. xR = firstPhi.Eval(&xR)
  25. var phi FourIsogeny
  26. for e := (372 - 4); e >= 0; e -= 2 {
  27. xS.Pow2k(&currentCurve, &xR, uint32(e))
  28. currentCurve, phi = ComputeFourIsogeny(&xS)
  29. xR = phi.Eval(&xR)
  30. xP = phi.Eval(&xP)
  31. xQ = phi.Eval(&xQ)
  32. xQmP = phi.Eval(&xQmP)
  33. }
  34. var invZP, invZQ, invZQmP ExtensionFieldElement
  35. ExtensionFieldBatch3Inv(&xP.z, &xQ.z, &xQmP.z, &invZP, &invZQ, &invZQmP)
  36. var publicKey SIDHPublicKeyAlice
  37. publicKey.affine_xP.Mul(&xP.x, &invZP)
  38. publicKey.affine_xQ.Mul(&xQ.x, &invZQ)
  39. publicKey.affine_xQmP.Mul(&xQmP.x, &invZQmP)
  40. return publicKey
  41. }
  42. // Perform Bob's (3-isogeny) key generation, using the slow but simple multiplication-based strategy.
  43. //
  44. // This function just exists to ensure that the fast isogeny-tree strategy works correctly.
  45. func bobKeyGenSlow(secretKey *SIDHSecretKeyBob) SIDHPublicKeyBob {
  46. var xP, xQ, xQmP, xR, xS ProjectivePoint
  47. xP.fromAffinePrimeField(&affine_xPA) // = ( x_P : 1) = x(P_A)
  48. xQ.fromAffinePrimeField(&affine_xPA) //
  49. xQ.x.Neg(&xQ.x) // = (-x_P : 1) = x(Q_A)
  50. xQmP = DistortAndDifference(&affine_xPA) // = x(Q_B - P_B)
  51. xR = SecretPoint(&affine_xPB, &affine_yPB, secretKey.scalar)
  52. var currentCurve ProjectiveCurveParameters
  53. // Starting curve has a = 0, so (A:C) = (0,1)
  54. currentCurve.A.Zero()
  55. currentCurve.C.One()
  56. var phi ThreeIsogeny
  57. for e := 238; e >= 0; e-- {
  58. xS.Pow3k(&currentCurve, &xR, uint32(e))
  59. currentCurve, phi = ComputeThreeIsogeny(&xS)
  60. xR = phi.Eval(&xR)
  61. xP = phi.Eval(&xP)
  62. xQ = phi.Eval(&xQ)
  63. xQmP = phi.Eval(&xQmP)
  64. }
  65. var invZP, invZQ, invZQmP ExtensionFieldElement
  66. ExtensionFieldBatch3Inv(&xP.z, &xQ.z, &xQmP.z, &invZP, &invZQ, &invZQmP)
  67. var publicKey SIDHPublicKeyBob
  68. publicKey.affine_xP.Mul(&xP.x, &invZP)
  69. publicKey.affine_xQ.Mul(&xQ.x, &invZQ)
  70. publicKey.affine_xQmP.Mul(&xQmP.x, &invZQmP)
  71. return publicKey
  72. }
  73. // Perform Alice's key agreement, using the slow but simple multiplication-based strategy.
  74. //
  75. // This function just exists to ensure that the fast isogeny-tree strategy works correctly.
  76. func aliceSharedSecretSlow(bobPublic *SIDHPublicKeyBob, aliceSecret *SIDHSecretKeyAlice) ExtensionFieldElement {
  77. var currentCurve = RecoverCurveParameters(&bobPublic.affine_xP, &bobPublic.affine_xQ, &bobPublic.affine_xQmP)
  78. var xR, xS, xP, xQ, xQmP ProjectivePoint
  79. xP.fromAffine(&bobPublic.affine_xP)
  80. xQ.fromAffine(&bobPublic.affine_xQ)
  81. xQmP.fromAffine(&bobPublic.affine_xQmP)
  82. xR.ThreePointLadder(&currentCurve, &xP, &xQ, &xQmP, aliceSecret.scalar)
  83. var firstPhi FirstFourIsogeny
  84. currentCurve, firstPhi = ComputeFirstFourIsogeny(&currentCurve)
  85. xR = firstPhi.Eval(&xR)
  86. var phi FourIsogeny
  87. for e := (372 - 4); e >= 2; e -= 2 {
  88. xS.Pow2k(&currentCurve, &xR, uint32(e))
  89. currentCurve, phi = ComputeFourIsogeny(&xS)
  90. xR = phi.Eval(&xR)
  91. }
  92. currentCurve, _ = ComputeFourIsogeny(&xR)
  93. return currentCurve.JInvariant()
  94. }
  95. // Perform Bob's key agreement, using the slow but simple multiplication-based strategy.
  96. //
  97. // This function just exists to ensure that the fast isogeny-tree strategy works correctly.
  98. func bobSharedSecretSlow(alicePublic *SIDHPublicKeyAlice, bobSecret *SIDHSecretKeyBob) ExtensionFieldElement {
  99. var currentCurve = RecoverCurveParameters(&alicePublic.affine_xP, &alicePublic.affine_xQ, &alicePublic.affine_xQmP)
  100. var xR, xS, xP, xQ, xQmP ProjectivePoint
  101. xP.fromAffine(&alicePublic.affine_xP)
  102. xQ.fromAffine(&alicePublic.affine_xQ)
  103. xQmP.fromAffine(&alicePublic.affine_xQmP)
  104. xR.ThreePointLadder(&currentCurve, &xP, &xQ, &xQmP, bobSecret.scalar)
  105. var phi ThreeIsogeny
  106. for e := 238; e >= 1; e-- {
  107. xS.Pow3k(&currentCurve, &xR, uint32(e))
  108. currentCurve, phi = ComputeThreeIsogeny(&xS)
  109. xR = phi.Eval(&xR)
  110. }
  111. currentCurve, _ = ComputeThreeIsogeny(&xR)
  112. return currentCurve.JInvariant()
  113. }
  114. func TestBobKeyGenFastVsSlow(t *testing.T) {
  115. // m_B = 3*randint(0,3^238)
  116. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  117. var bobSecretKey = SIDHSecretKeyBob{scalar: m_B[:]}
  118. var fastPubKey = bobSecretKey.PublicKey()
  119. var slowPubKey = bobKeyGenSlow(&bobSecretKey)
  120. if !fastPubKey.affine_xP.VartimeEq(&slowPubKey.affine_xP) {
  121. t.Error("Expected affine_xP = ", fastPubKey.affine_xP, "found", slowPubKey.affine_xP)
  122. }
  123. if !fastPubKey.affine_xQ.VartimeEq(&slowPubKey.affine_xQ) {
  124. t.Error("Expected affine_xQ = ", fastPubKey.affine_xQ, "found", slowPubKey.affine_xQ)
  125. }
  126. if !fastPubKey.affine_xQmP.VartimeEq(&slowPubKey.affine_xQmP) {
  127. t.Error("Expected affine_xQmP = ", fastPubKey.affine_xQmP, "found", slowPubKey.affine_xQmP)
  128. }
  129. }
  130. func TestAliceKeyGenFastVsSlow(t *testing.T) {
  131. // m_A = 2*randint(0,2^371)
  132. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  133. var aliceSecretKey = SIDHSecretKeyAlice{scalar: m_A[:]}
  134. var fastPubKey = aliceSecretKey.PublicKey()
  135. var slowPubKey = aliceKeyGenSlow(&aliceSecretKey)
  136. if !fastPubKey.affine_xP.VartimeEq(&slowPubKey.affine_xP) {
  137. t.Error("Expected affine_xP = ", fastPubKey.affine_xP, "found", slowPubKey.affine_xP)
  138. }
  139. if !fastPubKey.affine_xQ.VartimeEq(&slowPubKey.affine_xQ) {
  140. t.Error("Expected affine_xQ = ", fastPubKey.affine_xQ, "found", slowPubKey.affine_xQ)
  141. }
  142. if !fastPubKey.affine_xQmP.VartimeEq(&slowPubKey.affine_xQmP) {
  143. t.Error("Expected affine_xQmP = ", fastPubKey.affine_xQmP, "found", slowPubKey.affine_xQmP)
  144. }
  145. }
  146. func TestKeyAgreement(t *testing.T) {
  147. // m_A = 2*randint(0,2^371)
  148. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  149. // m_B = 3*randint(0,3^238)
  150. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  151. var aliceSecret = SIDHSecretKeyAlice{scalar: m_A[:]}
  152. var bobSecret = SIDHSecretKeyBob{scalar: m_B[:]}
  153. var alicePublic = aliceSecret.PublicKey()
  154. var bobPublic = bobSecret.PublicKey()
  155. var aliceSharedSecretSlow = aliceSharedSecretSlow(&bobPublic, &aliceSecret)
  156. var aliceSharedSecretFast = aliceSecret.SharedSecret(&bobPublic)
  157. var bobSharedSecretSlow = bobSharedSecretSlow(&alicePublic, &bobSecret)
  158. var bobSharedSecretFast = bobSecret.SharedSecret(&alicePublic)
  159. if !aliceSharedSecretFast.VartimeEq(&bobSharedSecretFast) {
  160. t.Error("Shared secret (fast) mismatch: Alice has ", aliceSharedSecretFast, " Bob has ", bobSharedSecretFast)
  161. }
  162. if !aliceSharedSecretSlow.VartimeEq(&bobSharedSecretSlow) {
  163. t.Error("Shared secret (slow) mismatch: Alice has ", aliceSharedSecretSlow, " Bob has ", bobSharedSecretSlow)
  164. }
  165. if !aliceSharedSecretSlow.VartimeEq(&bobSharedSecretFast) {
  166. t.Error("Shared secret mismatch: Alice (slow) has ", aliceSharedSecretSlow, " Bob (fast) has ", bobSharedSecretFast)
  167. }
  168. }
  169. func TestSecretPoint(t *testing.T) {
  170. // m_A = 2*randint(0,2^371)
  171. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  172. // m_B = 3*randint(0,3^238)
  173. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  174. var xR_A = SecretPoint(&affine_xPA, &affine_yPA, m_A[:])
  175. var xR_B = SecretPoint(&affine_xPB, &affine_yPB, m_B[:])
  176. var sageAffine_xR_A = ExtensionFieldElement{a: fp751Element{0x29f1dff12103d089, 0x7409b9bf955e0d87, 0xe812441c1cca7288, 0xc32b8b13efba55f9, 0xc3b76a80696d83da, 0x185dd4f93a3dc373, 0xfc07c1a9115b6717, 0x39bfcdd63b5c4254, 0xc4d097d51d41efd8, 0x4f893494389b21c7, 0x373433211d3d0446, 0x53c35ccc3d22}, b: fp751Element{0x722e718f33e40815, 0x8c5fc0fdf715667, 0x850fd292bbe8c74c, 0x212938a60fcbf5d3, 0xfdb2a099d58dc6e7, 0x232f83ab63c9c205, 0x23eda62fa5543f5e, 0x49b5758855d9d04f, 0x6b455e6642ef25d1, 0x9651162537470202, 0xfeced582f2e96ff0, 0x33a9e0c0dea8}}
  177. var sageAffine_xR_B = ExtensionFieldElement{a: fp751Element{0xdd4e66076e8499f5, 0xe7efddc6907519da, 0xe31f9955b337108c, 0x8e558c5479ffc5e1, 0xfee963ead776bfc2, 0x33aa04c35846bf15, 0xab77d91b23617a0d, 0xbdd70948746070e2, 0x66f71291c277e942, 0x187c39db2f901fce, 0x69262987d5d32aa2, 0xe1db40057dc}, b: fp751Element{0xd1b766abcfd5c167, 0x4591059dc8a382fa, 0x1ddf9490736c223d, 0xc96db091bdf2b3dd, 0x7b8b9c3dc292f502, 0xe5b18ad85e4d3e33, 0xc3f3479b6664b931, 0xa4f17865299e21e6, 0x3f7ef5b332fa1c6e, 0x875bedb5dab06119, 0x9b5a06ea2e23b93, 0x43d48296fb26}}
  178. var affine_xR_A = xR_A.toAffine()
  179. if !sageAffine_xR_A.VartimeEq(affine_xR_A) {
  180. t.Error("Expected \n", sageAffine_xR_A, "\nfound\n", affine_xR_A)
  181. }
  182. var affine_xR_B = xR_B.toAffine()
  183. if !sageAffine_xR_B.VartimeEq(affine_xR_B) {
  184. t.Error("Expected \n", sageAffine_xR_B, "\nfound\n", affine_xR_B)
  185. }
  186. }
  187. var keygenBenchPubKeyAlice SIDHPublicKeyAlice
  188. var keygenBenchPubKeyBob SIDHPublicKeyBob
  189. func BenchmarkAliceKeyGenFast(b *testing.B) {
  190. // m_A = 2*randint(0,2^371)
  191. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  192. var aliceSecretKey = SIDHSecretKeyAlice{scalar: m_A[:]}
  193. for n := 0; n < b.N; n++ {
  194. keygenBenchPubKeyAlice = aliceSecretKey.PublicKey()
  195. }
  196. }
  197. func BenchmarkAliceKeyGenSlow(b *testing.B) {
  198. // m_A = 2*randint(0,2^371)
  199. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  200. var aliceSecretKey = SIDHSecretKeyAlice{scalar: m_A[:]}
  201. for n := 0; n < b.N; n++ {
  202. keygenBenchPubKeyAlice = aliceKeyGenSlow(&aliceSecretKey)
  203. }
  204. }
  205. func BenchmarkBobKeyGenFast(b *testing.B) {
  206. // m_B = 3*randint(0,3^238)
  207. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  208. var bobSecretKey = SIDHSecretKeyBob{scalar: m_B[:]}
  209. for n := 0; n < b.N; n++ {
  210. keygenBenchPubKeyBob = bobSecretKey.PublicKey()
  211. }
  212. }
  213. func BenchmarkBobKeyGenSlow(b *testing.B) {
  214. // m_B = 3*randint(0,3^238)
  215. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  216. var bobSecretKey = SIDHSecretKeyBob{scalar: m_B[:]}
  217. for n := 0; n < b.N; n++ {
  218. keygenBenchPubKeyBob = bobKeyGenSlow(&bobSecretKey)
  219. }
  220. }
  221. var benchKeyAgreementAlicePublic = SIDHPublicKeyAlice{affine_xP: ExtensionFieldElement{a: fp751Element{0xea6b2d1e2aebb250, 0x35d0b205dc4f6386, 0xb198e93cb1830b8d, 0x3b5b456b496ddcc6, 0x5be3f0d41132c260, 0xce5f188807516a00, 0x54f3e7469ea8866d, 0x33809ef47f36286, 0x6fa45f83eabe1edb, 0x1b3391ae5d19fd86, 0x1e66daf48584af3f, 0xb430c14aaa87}, b: fp751Element{0x97b41ebc61dcb2ad, 0x80ead31cb932f641, 0x40a940099948b642, 0x2a22fd16cdc7fe84, 0xaabf35b17579667f, 0x76c1d0139feb4032, 0x71467e1e7b1949be, 0x678ca8dadd0d6d81, 0x14445daea9064c66, 0x92d161eab4fa4691, 0x8dfbb01b6b238d36, 0x2e3718434e4e}}, affine_xQ: ExtensionFieldElement{a: fp751Element{0xb055cf0ca1943439, 0xa9ff5de2fa6c69ed, 0x4f2761f934e5730a, 0x61a1dcaa1f94aa4b, 0xce3c8fadfd058543, 0xeac432aaa6701b8e, 0x8491d523093aea8b, 0xba273f9bd92b9b7f, 0xd8f59fd34439bb5a, 0xdc0350261c1fe600, 0x99375ab1eb151311, 0x14d175bbdbc5}, b: fp751Element{0xffb0ef8c2111a107, 0x55ceca3825991829, 0xdbf8a1ccc075d34b, 0xb8e9187bd85d8494, 0x670aa2d5c34a03b0, 0xef9fe2ed2b064953, 0xc911f5311d645aee, 0xf4411f409e410507, 0x934a0a852d03e1a8, 0xe6274e67ae1ad544, 0x9f4bc563c69a87bc, 0x6f316019681e}}, affine_xQmP: ExtensionFieldElement{a: fp751Element{0x6ffb44306a153779, 0xc0ffef21f2f918f3, 0x196c46d35d77f778, 0x4a73f80452edcfe6, 0x9b00836bce61c67f, 0x387879418d84219e, 0x20700cf9fc1ec5d1, 0x1dfe2356ec64155e, 0xf8b9e33038256b1c, 0xd2aaf2e14bada0f0, 0xb33b226e79a4e313, 0x6be576fad4e5}, b: fp751Element{0x7db5dbc88e00de34, 0x75cc8cb9f8b6e11e, 0x8c8001c04ebc52ac, 0x67ef6c981a0b5a94, 0xc3654fbe73230738, 0xc6a46ee82983ceca, 0xed1aa61a27ef49f0, 0x17fe5a13b0858fe0, 0x9ae0ca945a4c6b3c, 0x234104a218ad8878, 0xa619627166104394, 0x556a01ff2e7e}}}
  222. var benchKeyAgreementBobPublic = SIDHPublicKeyBob{affine_xP: ExtensionFieldElement{a: fp751Element{0x6e1b8b250595b5fb, 0x800787f5197d963b, 0x6f4a4e314162a8a4, 0xe75cba4d37c02128, 0x2212e7579817a216, 0xd8a5fdb0ab2f843c, 0x44230c9f998cfd6c, 0x311ff789b26aa292, 0x73d05c379ff53e40, 0xddd8f5a223bad56c, 0x94b611e6e931c8b5, 0x4d6b9bfe3555}, b: fp751Element{0x1a3686cfc8381294, 0x57f089b14f639cc4, 0xdb6a1565f2f5cabe, 0x83d67e8f6a02f215, 0x1946272593815e87, 0x2d839631785ca74c, 0xf149dcb2dee2bee, 0x705acd79efe405bf, 0xae3769b67687fbed, 0xacd5e29f2c203cb0, 0xdd91f08fa3153e08, 0x5a9ad8cb7400}}, affine_xQ: ExtensionFieldElement{a: fp751Element{0xd30ed48b8c0d0c4a, 0x949cad95959ec462, 0x188675581e9d1f2a, 0xf57ed3233d33031c, 0x564c6532f7283ce7, 0x80cbef8ee3b66ecb, 0x5c687359315f22ce, 0x1da950f8671fac50, 0x6fa6c045f513ef6, 0x25ffc65a8da12d4a, 0x8b0f4ac0f5244f23, 0xadcb0e07fd92}, b: fp751Element{0x37a43cd933ebfec4, 0x2a2806ef28dacf84, 0xd671fe718611b71e, 0xef7d73f01a676326, 0x99db1524e5799cf2, 0x860271dfbf67ff62, 0xedc2a0a14114bcf, 0x6c7b9b14b1264e5a, 0xf52de61707dc38b4, 0xccddb13fcc691f5a, 0x80f37a1220163920, 0x6a9175b9d5a1}}, affine_xQmP: ExtensionFieldElement{a: fp751Element{0xf08af9e695c626da, 0x7a4b4d52b54e1b38, 0x980272cd4c8b8c10, 0x1afcb6151d113176, 0xaef7dbd877c00f0c, 0xe8a5ea89078700c3, 0x520c1901aa8323fa, 0xfba049c947f3383a, 0x1c38abcab48be9af, 0x9f1212b923481ea, 0x1522da3457a7c293, 0xb746f78e3a61}, b: fp751Element{0x48010d0b48491128, 0x6d1c5c509f99f450, 0xaa3522330e3a8a62, 0x872aaf46193b2bb2, 0xc89260a2d8508973, 0x98bbbebf5524be83, 0x35711d01d895c217, 0x5e44e09ec506ed7, 0xac653a760ef6fd58, 0x5837954e30ad688d, 0xcbd3e9a1b5661da8, 0x15547f5d091a}}}
  223. var benchKeyAgreementJInvariant ExtensionFieldElement
  224. func BenchmarkKeyAgreementAliceFast(b *testing.B) {
  225. // m_A = 2*randint(0,2^371)
  226. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  227. var aliceSecret = SIDHSecretKeyAlice{scalar: m_A[:]}
  228. for n := 0; n < b.N; n++ {
  229. benchKeyAgreementJInvariant = aliceSecret.SharedSecret(&benchKeyAgreementBobPublic)
  230. }
  231. }
  232. func BenchmarkKeyAgreementAliceSlow(b *testing.B) {
  233. // m_A = 2*randint(0,2^371)
  234. var m_A = [...]uint8{248, 31, 9, 39, 165, 125, 79, 135, 70, 97, 87, 231, 221, 204, 245, 38, 150, 198, 187, 184, 199, 148, 156, 18, 137, 71, 248, 83, 111, 170, 138, 61, 112, 25, 188, 197, 132, 151, 1, 0, 207, 178, 24, 72, 171, 22, 11}
  235. var aliceSecret = SIDHSecretKeyAlice{scalar: m_A[:]}
  236. for n := 0; n < b.N; n++ {
  237. benchKeyAgreementJInvariant = aliceSharedSecretSlow(&benchKeyAgreementBobPublic, &aliceSecret)
  238. }
  239. }
  240. func BenchmarkKeyAgreementBobFast(b *testing.B) {
  241. // m_B = 3*randint(0,3^238)
  242. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  243. var bobSecret = SIDHSecretKeyBob{scalar: m_B[:]}
  244. for n := 0; n < b.N; n++ {
  245. benchKeyAgreementJInvariant = bobSecret.SharedSecret(&benchKeyAgreementAlicePublic)
  246. }
  247. }
  248. func BenchmarkKeyAgreementBobSlow(b *testing.B) {
  249. // m_B = 3*randint(0,3^238)
  250. var m_B = [...]uint8{246, 217, 158, 190, 100, 227, 224, 181, 171, 32, 120, 72, 92, 115, 113, 62, 103, 57, 71, 252, 166, 121, 126, 201, 55, 99, 213, 234, 243, 228, 171, 68, 9, 239, 214, 37, 255, 242, 217, 180, 25, 54, 242, 61, 101, 245, 78}
  251. var bobSecret = SIDHSecretKeyBob{scalar: m_B[:]}
  252. for n := 0; n < b.N; n++ {
  253. benchKeyAgreementJInvariant = bobSharedSecretSlow(&benchKeyAgreementAlicePublic, &bobSecret)
  254. }
  255. }