hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 2c4624269c783fb01d9ab5e4427d47ad8f5ad1c5
parent 91b36691accecacfbcf5ad11c44cbeb590114c13
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Thu,  7 Mar 2024 14:50:07 +0100

crypto::ec: add max sz constants for static allocation

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Diffstat:
Mcrypto/ec/types.ha | 8++++++++
Mcrypto/ec/validate.ha | 2+-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/crypto/ec/types.ha b/crypto/ec/types.ha @@ -3,6 +3,14 @@ use io; +// Maxium coordinate size of the modules curves in bits. +export def MAX_COORDBITSZ = 528z; + +// Maximum size of a point of the modules curves in bytes. +export def MAX_POINTSZ = P521_POINTSZ; + +// Maximum size of a scalar of the modules curves in bytes. +export def MAX_SCALARSZ = P521_SCALARSZ; // Interface for common operations over a specific curve. // diff --git a/crypto/ec/validate.ha b/crypto/ec/validate.ha @@ -16,7 +16,7 @@ export fn validate_pointformat(c: *curve, p: []u8) (void | invalid) = { export fn validate_point(c: *curve, p: []u8) (void | invalid) = { validate_pointformat(c, p)?; - static let scalarbuf: [133]u8 = [0...]; + static let scalarbuf: [MAX_POINTSZ]u8 = [0...]; let scalarbuf = scalarbuf[..len(c.order())]; scalarbuf[len(scalarbuf) - 1] = 1;