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.
 
 
 

115 lines
3.5 KiB

  1. package sidh
  2. import (
  3. // p503 "github.com/cloudflare/p751sidh/p503toolbox"
  4. p751 "github.com/cloudflare/p751sidh/p751toolbox"
  5. . "github.com/cloudflare/p751sidh/internal/utils"
  6. )
  7. type ctxCtor func() OperationContext
  8. type DomainParams struct {
  9. // P, Q and R=P-Q base points
  10. Affine_P, Affine_Q, Affine_R p751.ExtensionFieldElement
  11. // Max size of secret key for x-torsion group
  12. SecretBitLen uint
  13. // MaskBytes
  14. MaskBytes []byte
  15. // Size of a compuatation strategy for x-torsion group
  16. IsogenyStrategy []uint32
  17. }
  18. type SidhParams struct {
  19. Id PrimeFieldId
  20. // The secret key size, in bytes.
  21. SecretKeySize int
  22. // The public key size, in bytes.
  23. PublicKeySize int
  24. // The shared secret size, in bytes.
  25. SharedSecretSize uint
  26. // 2- and 3-torsion group parameter definitions
  27. A, B DomainParams
  28. // Sample rate to obtain a value in [0,3^238]
  29. SampleRate uint
  30. // Length of SIKE secret message. Must be one of {24,32,40},
  31. // depending on size of prime field used (see [SIKE], 1.4 and 5.1)
  32. MsgLen uint
  33. // Length of SIKE ephemeral KEM key (see [SIKE], 1.4 and 5.1)
  34. KemSize uint
  35. // Creates operation context
  36. op ctxCtor
  37. }
  38. // Keeps mapping: SIDH prime field ID to domain parameters
  39. var sidhParams = make(map[PrimeFieldId]SidhParams)
  40. // Params returns domain parameters corresponding to finite field and identified by
  41. // `id` provieded by the caller. Function panics in case `id` wasn't registered earlier.
  42. func Params(id PrimeFieldId) *SidhParams {
  43. if val, ok := sidhParams[id]; ok {
  44. return &val
  45. }
  46. panic("sidh: SIDH Params ID unregistered")
  47. }
  48. func init() {
  49. p751 := SidhParams{
  50. Id: FP_751,
  51. SecretKeySize: p751.P751_SecretKeySize,
  52. PublicKeySize: p751.P751_PublicKeySize,
  53. SharedSecretSize: p751.P751_SharedSecretSize,
  54. A: DomainParams{
  55. // OZAPTF: Probably not needed
  56. Affine_P: p751.P751_affine_PA,
  57. Affine_Q: p751.P751_affine_QA,
  58. Affine_R: p751.P751_affine_RA,
  59. SecretBitLen: p751.P751_SecretBitLenA,
  60. MaskBytes: []byte{p751.P751_MaskAliceByte1, p751.P751_MaskAliceByte2, p751.P751_MaskAliceByte3},
  61. IsogenyStrategy: p751.P751_AliceIsogenyStrategy[:],
  62. },
  63. B: DomainParams{
  64. Affine_P: p751.P751_affine_PB,
  65. Affine_Q: p751.P751_affine_QB,
  66. Affine_R: p751.P751_affine_RB,
  67. SecretBitLen: p751.P751_SecretBitLenB,
  68. MaskBytes: []byte{p751.P751_MaskBobByte},
  69. IsogenyStrategy: p751.P751_BobIsogenyStrategy[:],
  70. },
  71. MsgLen: 32,
  72. // SIKEp751 provides 192 bit of classical security ([SIKE], 5.1)
  73. KemSize: 24,
  74. SampleRate: p751.P751_SampleRate,
  75. op: p751.NewCtx,
  76. }
  77. /*
  78. p503 := SidhParams{
  79. Id: FP_503,
  80. SecretKeySize: P503_SecretKeySize,
  81. PublicKeySize: P503_PublicKeySize,
  82. SharedSecretSize: P503_SharedSecretSize,
  83. A: DomainParams{
  84. Affine_P: P503_affine_PA,
  85. Affine_Q: P503_affine_QA,
  86. Affine_R: P503_affine_RA,
  87. SecretBitLen: P503_SecretBitLenA,
  88. MaskBytes: []byte{P503_MaskAliceByte1, P503_MaskAliceByte2, P503_MaskAliceByte3},
  89. IsogenyStrategy: P503_AliceIsogenyStrategy[:],
  90. },
  91. B: DomainParams{
  92. Affine_P: P503_affine_PB,
  93. Affine_Q: P503_affine_QB,
  94. Affine_R: P503_affine_RB,
  95. SecretBitLen: P503_SecretBitLenB,
  96. MaskBytes: []byte{P751_MaskBobByte},
  97. IsogenyStrategy: P751_BobIsogenyStrategy[:],
  98. },
  99. MsgLen: 32,
  100. // SIKEp751 provides 192 bit of classical security ([SIKE], 5.1)
  101. KemSize: 24,
  102. SampleRate: P503_SampleRate,
  103. }
  104. */
  105. sidhParams[FP_751] = p751
  106. // sidhParams[FP_503] = p503
  107. }