Skip to content

Commit

Permalink
Fix DefaultProperties arrays in FCryptoEC_Prime
Browse files Browse the repository at this point in the history
  • Loading branch information
tuokri committed Aug 8, 2024
1 parent 12e1b40 commit f4fddeb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 70 deletions.
85 changes: 17 additions & 68 deletions Classes/FCryptoEC_Prime.uc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FCryptoEC_Prime extends Object
notplaceable;

`include(FCrypto\Classes\FCryptoMacros.uci);
`include(FCrypto\Classes\FCryptoEllipticCurveMacros.uci);

/*
* Parameters for supported curves:
Expand Down Expand Up @@ -147,12 +148,14 @@ static final function CurveParams IdToCurve(EFCEllipticCurve Curve)
static function array<byte> Generator(EFCEllipticCurve Curve, out int Len)
{
local array<byte> TODO;
TODO.Length = 0;
return TODO;
}

static function array<byte> Order(EFCEllipticCurve Curve, out int Len)
{
local array<byte> TODO;
TODO.Length = 0;
return TODO;
}

Expand Down Expand Up @@ -198,72 +201,18 @@ static function int MulAdd(

DefaultProperties
{
P256_P={(
0x0111,
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x003F, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x4000, 0x7FFF,
0x7FFF, 0x0001
)}
P256_R2={(
0x0111,
0x0000, 0x6000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FFC, 0x7FFF,
0x7FBF, 0x7FFF, 0x7FBF, 0x7FFF, 0x7FFF, 0x7FFF, 0x77FF, 0x7FFF,
0x4FFF, 0x0000
)}
P256_B={(
0x0111,
0x770C, 0x5EEF, 0x29C4, 0x3EC4, 0x6273, 0x0486, 0x4543, 0x3993,
0x3C01, 0x6B56, 0x212E, 0x57EE, 0x4882, 0x204B, 0x7483, 0x3C16,
0x0187, 0x0000
)}
P384_P={(
0x0199,
0x7FFF, 0x7FFF, 0x0003, 0x0000, 0x0000, 0x0000, 0x7FC0, 0x7FFF,
0x7EFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
0x7FFF, 0x01FF
)}
P384_R2={(
0x0199,
0x1000, 0x0000, 0x0000, 0x7FFF, 0x7FFF, 0x0001, 0x0000, 0x0010,
0x0000, 0x0000, 0x0000, 0x7F00, 0x7FFF, 0x01FF, 0x0000, 0x1000,
0x0000, 0x2000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000
)}
P384_B={(
0x0199,
0x7333, 0x2096, 0x70D1, 0x2310, 0x3020, 0x6197, 0x1464, 0x35BB,
0x70CA, 0x0117, 0x1920, 0x4136, 0x5FC8, 0x5713, 0x4938, 0x7DD2,
0x4DD2, 0x4A71, 0x0220, 0x683E, 0x2C87, 0x4DB1, 0x7BFF, 0x6C09,
0x0452, 0x0084
)}
P521_P={(
0x022B,
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,
0x7FFF, 0x7FFF, 0x07FF
)}
P521_R2={(
0x022B,
0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000
)}
P521_B={(
0x022B,
0x7002, 0x6A07, 0x751A, 0x228F, 0x71EF, 0x5869, 0x20F4, 0x1EFC,
0x7357, 0x37E0, 0x4EEC, 0x605E, 0x1652, 0x26F6, 0x31FA, 0x4A8F,
0x6193, 0x3C2A, 0x3C42, 0x48C7, 0x3489, 0x6771, 0x4C57, 0x5CCD,
0x2725, 0x545B, 0x503B, 0x5B42, 0x21A0, 0x2534, 0x687E, 0x70E4,
0x1618, 0x27D7, 0x0465
)}

// TODO: fix array assignments.
_PP(0)=(P=default.P256_P, B=default.P256_B, R2=default.P256_R2, P0i=0x001, PointLen=65)
_PP(1)=(P=default.P384_P, B=default.P384_B, R2=default.P384_R2, P0i=0x001, PointLen=97)
_PP(2)=(P=default.P521_P, B=default.P521_B, R2=default.P521_R2, P0i=0x001, PointLen=133)
// TODO: are these needed?
P256_P={(`P256_P_VALUES)}
P256_R2={(`P256_R2_VALUES)}
P256_B={(`P256_B_VALUES)}
P384_P={(`P384_P_VALUES)}
P384_R2={(`P384_R2_VALUES)}
P384_B={(`P384_B_VALUES)}
P521_P={(`P521_P_VALUES)}
P521_R2={(`P521_R2_VALUES)}
P521_B={(`P521_B_VALUES)}

_PP(0)={(P=(`P256_P_VALUES), B=(`P256_R2_VALUES), R2=(`P256_B_VALUES), P0i=0x001, PointLen=65)}
_PP(1)={(P=(`P384_P_VALUES), B=(`P384_B_VALUES), R2=(`P384_R2_VALUES), P0i=0x001, PointLen=97)}
_PP(2)={(P=(`P521_P_VALUES), B=(`P521_B_VALUES), R2=(`P521_R2_VALUES), P0i=0x001, PointLen=133)}
}
64 changes: 64 additions & 0 deletions Classes/FCryptoEllipticCurveMacros.uci
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
`define BR_MAX_EC_SIZE 528

`define P256_P_VALUES \
0x0111, \
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x003F, 0x0000, \
0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x4000, 0x7FFF, \
0x7FFF, 0x0001

`define P256_R2_VALUES \
0x0111, \
0x0000, 0x6000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FFC, 0x7FFF, \
0x7FBF, 0x7FFF, 0x7FBF, 0x7FFF, 0x7FFF, 0x7FFF, 0x77FF, 0x7FFF, \
0x4FFF, 0x0000

`define P256_B_VALUES \
0x0111, \
0x770C, 0x5EEF, 0x29C4, 0x3EC4, 0x6273, 0x0486, 0x4543, 0x3993, \
0x3C01, 0x6B56, 0x212E, 0x57EE, 0x4882, 0x204B, 0x7483, 0x3C16, \
0x0187, 0x0000

`define P384_P_VALUES \
0x0199, \
0x7FFF, 0x7FFF, 0x0003, 0x0000, 0x0000, 0x0000, 0x7FC0, 0x7FFF, \
0x7EFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, \
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, \
0x7FFF, 0x01FF

`define P384_R2_VALUES \
0x0199, \
0x1000, 0x0000, 0x0000, 0x7FFF, 0x7FFF, 0x0001, 0x0000, 0x0010, \
0x0000, 0x0000, 0x0000, 0x7F00, 0x7FFF, 0x01FF, 0x0000, 0x1000, \
0x0000, 0x2000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, \
0x0000, 0x0000

`define P384_B_VALUES \
0x0199, \
0x7333, 0x2096, 0x70D1, 0x2310, 0x3020, 0x6197, 0x1464, 0x35BB, \
0x70CA, 0x0117, 0x1920, 0x4136, 0x5FC8, 0x5713, 0x4938, 0x7DD2, \
0x4DD2, 0x4A71, 0x0220, 0x683E, 0x2C87, 0x4DB1, 0x7BFF, 0x6C09, \
0x0452, 0x0084

`define P521_P_VALUES \
0x022B, \
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, \
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, \
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, \
0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, \
0x7FFF, 0x7FFF, 0x07FF

`define P521_R2_VALUES \
0x022B, \
0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, \
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, \
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, \
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, \
0x0000, 0x0000, 0x0000

`define P521_B_VALUES \
0x022B, \
0x7002, 0x6A07, 0x751A, 0x228F, 0x71EF, 0x5869, 0x20F4, 0x1EFC, \
0x7357, 0x37E0, 0x4EEC, 0x605E, 0x1652, 0x26F6, 0x31FA, 0x4A8F, \
0x6193, 0x3C2A, 0x3C42, 0x48C7, 0x3489, 0x6771, 0x4C57, 0x5CCD, \
0x2725, 0x545B, 0x503B, 0x5B42, 0x21A0, 0x2534, 0x687E, 0x70E4, \
0x1618, 0x27D7, 0x0465
2 changes: 0 additions & 2 deletions Classes/FCryptoMacros.uci
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@

const SIZEOF_UINT16_T = 2;
const WORD_SIZE = 15;

`define BR_MAX_EC_SIZE 528

0 comments on commit f4fddeb

Please sign in to comment.