Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OcCryptoLib: Add Streebog support #377

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 83 additions & 14 deletions Include/Acidanthera/Library/OcCryptoLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,35 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// Set supported hashes to all by default.
//
#ifndef CONFIG_HAS_SUPPORTED_HASHES
#define OC_CRYPTO_SUPPORTS_SHA256 1
#define OC_CRYPTO_SUPPORTS_SHA384 1
#define OC_CRYPTO_SUPPORTS_SHA512 1
#define OC_CRYPTO_SUPPORTS_SHA1 1
#define OC_CRYPTO_SUPPORTS_MD5 1
#define OC_CRYPTO_SUPPORTS_SHA256 1
#define OC_CRYPTO_SUPPORTS_SHA384 1
#define OC_CRYPTO_SUPPORTS_SHA512 1
#define OC_CRYPTO_SUPPORTS_SHA1 1
#define OC_CRYPTO_SUPPORTS_MD5 1
#define OC_CRYPTO_SUPPORTS_STREEBOG 1
#endif

//
// Digest sizes.
//
#define MD5_DIGEST_SIZE 16
#define SHA1_DIGEST_SIZE 20
#define SHA256_DIGEST_SIZE 32
#define SHA384_DIGEST_SIZE 48
#define SHA512_DIGEST_SIZE 64
#define MD5_DIGEST_SIZE 16
#define SHA1_DIGEST_SIZE 20
#define SHA256_DIGEST_SIZE 32
#define SHA384_DIGEST_SIZE 48
#define SHA512_DIGEST_SIZE 64
#define STREEBOG256_DIGEST_SIZE 256
#define STREEBOG512_DIGEST_SIZE 512

#define OC_MAX_SHA_DIGEST_SIZE SHA512_DIGEST_SIZE
#define OC_MAX_SHA_DIGEST_SIZE STREEBOG512_DIGEST_SIZE

//
// Block sizes.
//
#define SHA256_BLOCK_SIZE 64
#define SHA512_BLOCK_SIZE 128
#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
#define SHA256_BLOCK_SIZE 64
#define SHA512_BLOCK_SIZE 128
#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
#define STREEBOG256_BLOCK_SIZE 512
#define STREEBOG512_BLOCK_SIZE STREEBOG256_BLOCK_SIZE

//
// Derived parameters.
Expand Down Expand Up @@ -145,6 +150,20 @@ typedef struct SHA512_CONTEXT_ {

typedef SHA512_CONTEXT SHA384_CONTEXT;

typedef struct UINT512_ {
UINT64 QWORD[8];
} UINT512;

typedef struct STREEBOG_CONTEXT_ {
UINT8 buffer[64];
UINT512 hash;
UINT512 h;
UINT512 N;
UINT512 Sigma;
UINT32 bufsize;
UINT32 digest_size;
} STREEBOG_CONTEXT;

///
/// The structure describing the RSA Public Key format.
/// The exponent is always 65537.
Expand Down Expand Up @@ -394,6 +413,56 @@ Sha384 (
UINTN Len
);

VOID
Streebog256Init (
STREEBOG_CONTEXT *Context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IN and OUT specifiers are missing, for all.

);

VOID
Streebog256Update (
STREEBOG_CONTEXT *Context,
CONST UINT8 *Data,
UINT32 Length
);

VOID
Streebog256Final (
STREEBOG_CONTEXT *Context,
UINT8 *HashDigest
);

VOID
Streebog256 (
CONST UINT8 *Data,
UINT8 *Digest,
UINT32 Length
);

VOID
Streebog512Init (
STREEBOG_CONTEXT *Context
);

VOID
Streebog512Update (
STREEBOG_CONTEXT *Context,
CONST UINT8 *Data,
UINT32 Length
);

VOID
Streebog512Final (
STREEBOG_CONTEXT *Context,
UINT8 *Digest
);

VOID
Streebog512 (
CONST UINT8 *Data,
UINT8 *Digest,
UINT32 Length
);

BOOLEAN
EFIAPI
TryEnableAccel (
Expand Down
2 changes: 2 additions & 0 deletions Library/OcCryptoLib/OcCryptoLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
RsaDigitalSign.c
Sha1.c
Sha2.c
Streebog.h
Streebog.c
SecureMem.c
PasswordHash.c
BigNumLib.h
Expand Down
Loading
Loading