Skip to content

Commit

Permalink
Refactor SHA2 constants, fix typo bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tuokri committed Aug 6, 2024
1 parent ca4f737 commit e1a4566
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Classes/FCryptoContext.uc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class FCryptoContext extends Object
abstract
notplaceable;

`include(FCrypto\Classes\FCryptoSHA2Constants.uci);

struct FCryptoHashContext
{
// TODO: might need to use QWORD for this?
Expand All @@ -50,5 +52,13 @@ struct FCryptoSHA224Context extends FCryptoHashContext

StructDefaultProperties
{
Val(0)=SHA224_IV_VAL0
Val(1)=SHA224_IV_VAL1
Val(2)=SHA224_IV_VAL2
Val(3)=SHA224_IV_VAL3
Val(4)=SHA224_IV_VAL4
Val(5)=SHA224_IV_VAL5
Val(6)=SHA224_IV_VAL6
Val(7)=SHA224_IV_VAL7
}
};
11 changes: 6 additions & 5 deletions Classes/FCryptoSHA2.uc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FCryptoSHA2 extends Object;

`include(FCrypto\Classes\FCryptoMacros.uci);
`include(FCrypto\Classes\FCryptoSHA2Macros.uci);
`include(FCrypto\Classes\FCryptoSHA2Constants.uci);

var const array<int> SHA224_IV;
var const array<int> SHA256_IV;
Expand Down Expand Up @@ -279,6 +280,7 @@ static final function RangeEnc32BE_SVal8(
}
}

// TODO: do we need this in UScript?
static final function Sha224Init(out FCryptoSHA224Context Cc)
{
Cc.Val[0] = default.SHA224_IV[0];
Expand All @@ -287,9 +289,8 @@ static final function Sha224Init(out FCryptoSHA224Context Cc)
Cc.Val[3] = default.SHA224_IV[3];
Cc.Val[4] = default.SHA224_IV[4];
Cc.Val[5] = default.SHA224_IV[5];
Cc.Val[5] = default.SHA224_IV[5];
Cc.Val[6] = default.SHA224_IV[6];
Cc.Val[7] = default.SHA224_IV[7];
Cc.Val[5] = default.SHA224_IV[6];
Cc.Val[6] = default.SHA224_IV[7];
}

// TODO: what's the point of this abstraction?
Expand All @@ -314,8 +315,8 @@ static final function Sha256Update(
DefaultProperties
{
SHA224_IV={(
0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939,
0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4
SHA224_IV_VAL0, SHA224_IV_VAL1, SHA224_IV_VAL2, SHA224_IV_VAL3,
SHA224_IV_VAL4, SHA224_IV_VAL5, SHA224_IV_VAL6, SHA224_IV_VAL7
)}

SHA256_IV={(
Expand Down
8 changes: 8 additions & 0 deletions Classes/FCryptoSHA2Constants.uci
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const SHA224_IV_VAL0 = 0xC1059ED8;
const SHA224_IV_VAL1 = 0x367CD507;
const SHA224_IV_VAL2 = 0x3070DD17;
const SHA224_IV_VAL3 = 0xF70E5939;
const SHA224_IV_VAL4 = 0xFFC00B31;
const SHA224_IV_VAL5 = 0x68581511;
const SHA224_IV_VAL6 = 0x64F98FA7;
const SHA224_IV_VAL7 = 0xBEFA4FA4;

0 comments on commit e1a4566

Please sign in to comment.