forked from skair39/milagro-crypto-c
/
AMCLParameters.cmake
197 lines (178 loc) · 11.3 KB
/
AMCLParameters.cmake
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
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
cmake_minimum_required(VERSION 3.1)
# This file defines the parameters for the various curves and RSA
# levels supported by AMCL.
#
# The parameters can be accessed individually by name using the
# `amcl_curve_field(<field> <curve>)` and `amcl_rsa_field(<field>
# <level>)` functions in this file.
#
# The parameters can be loaded into the variables using the
# `amcl_load_curve(<curve>)` and `amcl_load_rsa(<level>)` macros in
# this file.
#
# The sister module `AMCLExpand.cmake` contains helper functions to
# expand template sources with the parameters defined here.
#######################################
# AMCL Curve parameters
#######################################
set(AMCL_CURVE_FIELDS TB TF TC NB BASE NBT M8 MT CT PF ST SX )
set(AMCL_CURVE_64_ED25519 256 25519 ED25519 32 56 255 5 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_C25519 256 25519 C25519 32 56 255 5 PSEUDO_MERSENNE MONTGOMERY NOT . . )
set(AMCL_CURVE_64_NIST256 256 NIST256 NIST256 32 56 256 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_BRAINPOOL 256 BRAINPOOL BRAINPOOL 32 56 256 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_ANSSI 256 ANSSI ANSSI 32 56 256 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_HIFIVE 336 HIFIVE HIFIVE 42 60 336 5 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_GOLDILOCKS 448 GOLDILOCKS GOLDILOCKS 56 58 448 7 GENERALISED_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_NIST384 384 NIST384 NIST384 48 56 384 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_C41417 416 C41417 C41417 52 60 414 7 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_NIST521 528 NIST521 NIST521 66 60 521 7 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_NUMS256W 256 256PMW NUMS256W 32 56 256 3 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_NUMS256E 256 256PME NUMS256E 32 56 256 3 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_NUMS384W 384 384PM NUMS384W 48 56 384 3 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_NUMS384E 384 384PM NUMS384E 48 56 384 3 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_NUMS512W 512 512PM NUMS512W 64 56 512 7 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_64_NUMS512E 512 512PM NUMS512E 64 56 512 7 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_64_BN254 256 BN254 BN254 32 56 254 3 NOT_SPECIAL WEIERSTRASS BN D_TYPE NEGATIVEX)
set(AMCL_CURVE_64_BN254CX 256 BN254CX BN254CX 32 56 254 3 NOT_SPECIAL WEIERSTRASS BN D_TYPE NEGATIVEX)
set(AMCL_CURVE_64_BLS383 384 BLS383 BLS383 48 56 383 3 NOT_SPECIAL WEIERSTRASS BLS D_TYPE POSITIVEX)
set(AMCL_CURVE_64_FP256BN 256 FP256BN FP256BN 32 56 256 3 NOT_SPECIAL WEIERSTRASS BN M_TYPE NEGATIVEX)
set(AMCL_CURVE_64_FP512BN 512 FP512BN FP512BN 64 60 512 3 NOT_SPECIAL WEIERSTRASS BN M_TYPE POSITIVEX)
set(AMCL_CURVE_64_BLS461 464 BLS461 BLS461 58 60 461 3 NOT_SPECIAL WEIERSTRASS BLS M_TYPE NEGATIVEX)
# ( TB TF TC NB BASE NBT M8 MT CT PF ST SX )
set(AMCL_CURVE_32_ED25519 256 25519 ED25519 32 29 255 5 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_C25519 256 25519 C25519 32 29 255 5 PSEUDO_MERSENNE MONTGOMERY NOT . . )
set(AMCL_CURVE_32_NIST256 256 NIST256 NIST256 32 28 256 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_BRAINPOOL 256 BRAINPOOL BRAINPOOL 32 28 256 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_ANSSI 256 ANSSI ANSSI 32 28 256 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_HIFIVE 336 HIFIVE HIFIVE 42 29 336 5 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_GOLDILOCKS 448 GOLDILOCKS GOLDILOCKS 56 29 448 7 GENERALISED_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_NIST384 384 NIST384 NIST384 48 29 384 7 NOT_SPECIAL WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_C41417 416 C41417 C41417 52 29 414 7 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_NIST521 528 NIST521 NIST521 66 28 521 7 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_NUMS256W 256 256PMW NUMS256W 32 28 256 3 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_NUMS256E 256 256PME NUMS256E 32 29 256 3 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_NUMS384W 384 384PM NUMS384W 48 29 384 3 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_NUMS384E 384 384PM NUMS384E 48 29 384 3 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_NUMS512W 512 512PM NUMS512W 64 29 512 7 PSEUDO_MERSENNE WEIERSTRASS NOT . . )
set(AMCL_CURVE_32_NUMS512E 512 512PM NUMS512E 64 29 512 7 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_32_BN254 256 BN254 BN254 32 28 254 3 NOT_SPECIAL WEIERSTRASS BN D_TYPE NEGATIVEX)
set(AMCL_CURVE_32_BN254CX 256 BN254CX BN254CX 32 28 254 3 NOT_SPECIAL WEIERSTRASS BN D_TYPE NEGATIVEX)
set(AMCL_CURVE_32_BLS383 384 BLS383 BLS383 48 29 383 3 NOT_SPECIAL WEIERSTRASS BLS D_TYPE POSITIVEX)
set(AMCL_CURVE_32_FP256BN 256 FP256BN FP256BN 32 28 256 3 NOT_SPECIAL WEIERSTRASS BN M_TYPE NEGATIVEX)
set(AMCL_CURVE_32_FP512BN 512 FP512BN FP512BN 64 29 512 3 NOT_SPECIAL WEIERSTRASS BN M_TYPE POSITIVEX)
set(AMCL_CURVE_32_BLS461 464 BLS461 BLS461 58 28 461 3 NOT_SPECIAL WEIERSTRASS BLS M_TYPE NEGATIVEX)
# ( TB TF TC NB BASE NBT M8 MT CT PF ST SX )
set(AMCL_CURVE_16_ED25519 256 25519 ED25519 32 13 255 5 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_16_NUMS256E 256 256PME NUMS256E 32 13 256 3 PSEUDO_MERSENNE EDWARDS NOT . . )
set(AMCL_CURVE_16_BN254 256 BN254 BN254 32 13 254 3 NOT_SPECIAL WEIERSTRASS BN D_TYPE NEGATIVEX)
set(AMCL_CURVE_16_BN254CX 256 BN254CX BN254CX 32 13 254 3 NOT_SPECIAL WEIERSTRASS BN D_TYPE NEGATIVEX)
#######################################
# AMCL RSA parameters
#######################################
set(AMCL_RSA_FIELDS TB TFF NB BASE ML)
set(AMCL_RSA_64_2048 1024 2048 128 58 2 )
set(AMCL_RSA_64_3072 384 3072 48 56 8 )
set(AMCL_RSA_64_4096 512 4096 64 60 8 )
# ( TB TFF NB BASE ML)
set(AMCL_RSA_32_2048 1024 2048 128 28 2 )
set(AMCL_RSA_32_3072 384 3072 48 28 8 )
set(AMCL_RSA_32_4096 512 4096 64 29 8 )
# ( TB TFF NB BASE ML)
set(AMCL_RSA_16_2048 256 2048 32 13 8 )
########################################
# Get supported curves and RSA levels
########################################
function(amcl_supported_curves output word_size)
get_cmake_property(_allvars VARIABLES)
string(REGEX MATCHALL "AMCL_CURVE_${word_size}_[a-zA-Z0-9]*" _amcl_curve_vars "${_allvars}")
string(REGEX REPLACE "AMCL_CURVE_[0-9][0-9]_" "" _names "${_amcl_curve_vars}")
list(REMOVE_DUPLICATES _names)
set("${output}" "${_names}" PARENT_SCOPE)
endfunction()
function(amcl_supported_rsa_levels output word_size)
get_cmake_property(_allvars VARIABLES)
string(REGEX MATCHALL "AMCL_RSA_${word_size}_[0-9]*" _amcl_rsa_vars "${_allvars}")
string(REGEX REPLACE "AMCL_RSA_[0-9][0-9]_" "" _names "${_amcl_rsa_vars}")
list(REMOVE_DUPLICATES _names)
set("${output}" "${_names}" PARENT_SCOPE)
endfunction()
#######################################
# AMCL parameters accessors
#######################################
# Loads the parameters for <curve> into variables in the calling
# scope.
macro(amcl_load_curve curve)
if(NOT AMCL_CURVE_${WORD_SIZE}_${curve})
message(FATAL_ERROR "Invalid curve: ${curve} for word size ${WORD_SIZE}")
endif()
# Export all predefined fields
foreach(field ${AMCL_CURVE_FIELDS})
list(FIND AMCL_CURVE_FIELDS "${field}" index)
list(GET AMCL_CURVE_${WORD_SIZE}_${curve} ${index} ${field})
endforeach()
# Export computed fields
# - BD
set(BD "${TB}_${BASE}")
# - SH
math(EXPR SH "${BASE} * (1 + ((8 * ${NB} - 1) / ${BASE})) - ${NBT}")
if (SH GREATER "30")
set(SH "30")
endif()
endmacro()
# Loads the parameters for RSA <level> into variables in the calling
# scope.
macro(amcl_load_rsa level)
if(NOT AMCL_RSA_${WORD_SIZE}_${level})
message(FATAL_ERROR "Invalid RSA level: ${level} for word size ${WORD_SIZE}")
endif()
# Export all predefined fields
foreach(field ${AMCL_RSA_FIELDS})
list(FIND AMCL_RSA_FIELDS "${field}" index)
list(GET AMCL_RSA_${WORD_SIZE}_${level} ${index} ${field})
endforeach()
# Export computed fields
# - BD
set(BD "${TB}_${BASE}")
endmacro()
# Retrieves the value of <field> for <curve>.
#
# If the optional `DEST <name>` argument is supplied, the value is
# saved to <name> in the calling scope. Otherwise, it is saved to
# <field> in the calling scope.
function(amcl_curve_field field curve)
cmake_parse_arguments(amcl_curve_field "" "DEST" "" ${ARGN})
if(NOT amcl_curve_field_DEST)
set(amcl_curve_field_DEST ${field})
endif()
amcl_load_curve(${curve})
set("${amcl_curve_field_DEST}" "${${field}}" PARENT_SCOPE)
endfunction()
# Retrieves the value of <field> for RSA <level>.
#
# If the optional `DEST <name>` argument is supplied, the value is
# saved to <name> in the calling scope. Otherwise, it is saved to
# <field> in the calling scope.
function(amcl_rsa_field field level)
cmake_parse_arguments(amcl_rsa_field "" "DEST" "" ${ARGN})
if(NOT amcl_rsa_field_DEST)
set(amcl_rsa_field_DEST ${field})
endif()
amcl_load_rsa(${level})
set("${amcl_rsa_field_DEST}" "${${field}}" PARENT_SCOPE)
endfunction()