aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-03-12 06:23:39 -0500
committerJack Lloyd <[email protected]>2021-03-12 06:23:39 -0500
commit8fc604a9126ad8d8a0300ab3c6ce427c552abecd (patch)
tree8247e6ccc8eace3ff09698341505f2364f0a4786 /src/scripts
parent3c89767a9b0a6d333aad32100a2e206f37b8cb43 (diff)
Format small integers using decimal
Diffstat (limited to 'src/scripts')
-rwxr-xr-xsrc/scripts/gen_ec_groups.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/scripts/gen_ec_groups.py b/src/scripts/gen_ec_groups.py
index 67eabad63..6f5aac04d 100755
--- a/src/scripts/gen_ec_groups.py
+++ b/src/scripts/gen_ec_groups.py
@@ -43,6 +43,11 @@ def curve_info(src):
yield current
current = {}
+def format_int(x):
+ if x.bit_length() <= 5:
+ return str(x)
+ return hex(x).upper().replace('0X', '0x')
+
def print_curve(curve):
template_str = """ // %s
if(%s)
@@ -57,12 +62,12 @@ def print_curve(curve):
name = curve['Name']
oids = ['OID{%s}' % (oid.replace('.', ',')) for oid in curve['OID']]
- p = hex(curve['P']).upper().replace('0X', '0x')
- a = hex(curve['A']).upper().replace('0X', '0x')
- b = hex(curve['B']).upper().replace('0X', '0x')
- x = hex(curve['X']).upper().replace('0X', '0x')
- y = hex(curve['Y']).upper().replace('0X', '0x')
- n = hex(curve['N']).upper().replace('0X', '0x')
+ p = format_int(curve['P'])
+ a = format_int(curve['A'])
+ b = format_int(curve['B'])
+ x = format_int(curve['X'])
+ y = format_int(curve['Y'])
+ n = format_int(curve['N'])
oid_match = ' || '.join(['oid == %s' % oid for oid in oids])