Skip to content
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
2 changes: 1 addition & 1 deletion provider/ALGORITHM_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ None yet.

| Family | Variants |
|---|---|
| SHA-2 | `SHA2-224`, `SHA2-256` |
| SHA-2 | `SHA2-224`, `SHA2-256`, `SHA2-384`, `SHA2-512`, `SHA2-512/224`, `SHA2-512/256` |

## Key Encapsulation Mechanisms (`OSSL_OP_KEM`)

Expand Down
154 changes: 154 additions & 0 deletions provider/backend/operations/digests/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,157 @@ int awslc_prov_sha256_copy(void *dst, const void *src) {
*(SHA256_CTX *)dst = *(const SHA256_CTX *)src;
return 1;
}

// SHA-384

size_t awslc_prov_sha384_ctx_size(void) { return sizeof(SHA512_CTX); }

size_t awslc_prov_sha384_digest_size(void) { return SHA384_DIGEST_LENGTH; }

size_t awslc_prov_sha384_block_size(void) { return SHA384_CBLOCK; }

int awslc_prov_sha384_init(void *ctx) {
if (ctx == NULL) {
return 0;
}
return SHA384_Init((SHA512_CTX *)ctx);
}

int awslc_prov_sha384_update(void *ctx, const void *data, size_t len) {
if (ctx == NULL || (data == NULL && len != 0)) {
return 0;
}
return SHA384_Update((SHA512_CTX *)ctx, data, len);
}

int awslc_prov_sha384_final(void *ctx, unsigned char *out, size_t out_size) {
if (ctx == NULL || out == NULL || out_size < SHA384_DIGEST_LENGTH) {
return 0;
}
return SHA384_Final(out, (SHA512_CTX *)ctx);
}

int awslc_prov_sha384_copy(void *dst, const void *src) {
if (dst == NULL || src == NULL) {
return 0;
}
*(SHA512_CTX *)dst = *(const SHA512_CTX *)src;
return 1;
}

// SHA-512

size_t awslc_prov_sha512_ctx_size(void) { return sizeof(SHA512_CTX); }

size_t awslc_prov_sha512_digest_size(void) { return SHA512_DIGEST_LENGTH; }

size_t awslc_prov_sha512_block_size(void) { return SHA512_CBLOCK; }

int awslc_prov_sha512_init(void *ctx) {
if (ctx == NULL) {
return 0;
}
return SHA512_Init((SHA512_CTX *)ctx);
}

int awslc_prov_sha512_update(void *ctx, const void *data, size_t len) {
if (ctx == NULL || (data == NULL && len != 0)) {
return 0;
}
return SHA512_Update((SHA512_CTX *)ctx, data, len);
}

int awslc_prov_sha512_final(void *ctx, unsigned char *out, size_t out_size) {
if (ctx == NULL || out == NULL || out_size < SHA512_DIGEST_LENGTH) {
return 0;
}
return SHA512_Final(out, (SHA512_CTX *)ctx);
}

int awslc_prov_sha512_copy(void *dst, const void *src) {
if (dst == NULL || src == NULL) {
return 0;
}
*(SHA512_CTX *)dst = *(const SHA512_CTX *)src;
return 1;
}

// SHA-512/224

size_t awslc_prov_sha512_224_ctx_size(void) { return sizeof(SHA512_CTX); }

size_t awslc_prov_sha512_224_digest_size(void) {
return SHA512_224_DIGEST_LENGTH;
}

size_t awslc_prov_sha512_224_block_size(void) { return SHA512_CBLOCK; }

int awslc_prov_sha512_224_init(void *ctx) {
if (ctx == NULL) {
return 0;
}
return SHA512_224_Init((SHA512_CTX *)ctx);
}

int awslc_prov_sha512_224_update(void *ctx, const void *data, size_t len) {
if (ctx == NULL || (data == NULL && len != 0)) {
return 0;
}
return SHA512_224_Update((SHA512_CTX *)ctx, data, len);
}

int awslc_prov_sha512_224_final(void *ctx, unsigned char *out,
size_t out_size) {
if (ctx == NULL || out == NULL || out_size < SHA512_224_DIGEST_LENGTH) {
return 0;
}
return SHA512_224_Final(out, (SHA512_CTX *)ctx);
}

int awslc_prov_sha512_224_copy(void *dst, const void *src) {
if (dst == NULL || src == NULL) {
return 0;
}
*(SHA512_CTX *)dst = *(const SHA512_CTX *)src;
return 1;
}

// SHA-512/256

size_t awslc_prov_sha512_256_ctx_size(void) { return sizeof(SHA512_CTX); }

size_t awslc_prov_sha512_256_digest_size(void) {
return SHA512_256_DIGEST_LENGTH;
}

size_t awslc_prov_sha512_256_block_size(void) { return SHA512_CBLOCK; }

int awslc_prov_sha512_256_init(void *ctx) {
if (ctx == NULL) {
return 0;
}
return SHA512_256_Init((SHA512_CTX *)ctx);
}

int awslc_prov_sha512_256_update(void *ctx, const void *data, size_t len) {
if (ctx == NULL || (data == NULL && len != 0)) {
return 0;
}
return SHA512_256_Update((SHA512_CTX *)ctx, data, len);
}

int awslc_prov_sha512_256_final(void *ctx, unsigned char *out,
size_t out_size) {
if (ctx == NULL || out == NULL || out_size < SHA512_256_DIGEST_LENGTH) {
return 0;
}
return SHA512_256_Final(out, (SHA512_CTX *)ctx);
}

int awslc_prov_sha512_256_copy(void *dst, const void *src) {
if (dst == NULL || src == NULL) {
return 0;
}
*(SHA512_CTX *)dst = *(const SHA512_CTX *)src;
return 1;
}
188 changes: 188 additions & 0 deletions provider/frontend/operations/digests/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,191 @@ static int awslc_prov_sha256_get_params(OSSL_PARAM params[]) {
}

AWSLC_PROV_FIXED_DIGEST_DISPATCH_TABLE(sha256);

// SHA-384

AWSLC_PROV_DECLARE_FIXED_DIGEST_SLOTS(sha384);

static void *awslc_prov_sha384_newctx(void *provctx) {
(void)provctx;
return awslc_prov_zalloc(awslc_prov_sha384_ctx_size());
}

static void awslc_prov_sha384_freectx(void *dctx) {
awslc_prov_sha2_freectx(dctx, awslc_prov_sha384_ctx_size());
}

static void *awslc_prov_sha384_dupctx(void *dctx) {
return awslc_prov_sha2_dupctx(dctx, awslc_prov_sha384_ctx_size(),
awslc_prov_sha384_copy);
}

static void awslc_prov_sha384_copyctx(void *outctx, void *inctx) {
awslc_prov_sha2_copyctx(outctx, inctx, awslc_prov_sha384_copy);
}

static int awslc_prov_sha384_init_op(void *dctx, const OSSL_PARAM params[]) {
return awslc_prov_sha2_init_op(dctx, params, awslc_prov_sha384_init);
}

static int awslc_prov_sha384_update_op(void *dctx, const unsigned char *in,
size_t inl) {
return awslc_prov_sha2_update_op(dctx, in, inl, awslc_prov_sha384_update);
}

static int awslc_prov_sha384_final_op(void *dctx, unsigned char *out,
size_t *outl, size_t outsz) {
return awslc_prov_sha2_final_op(dctx, out, outl, outsz,
awslc_prov_sha384_final,
awslc_prov_sha384_digest_size());
}

static int awslc_prov_sha384_get_params(OSSL_PARAM params[]) {
return awslc_prov_sha2_get_params(params, awslc_prov_sha384_block_size(),
awslc_prov_sha384_digest_size());
}

AWSLC_PROV_FIXED_DIGEST_DISPATCH_TABLE(sha384);

// SHA-512

AWSLC_PROV_DECLARE_FIXED_DIGEST_SLOTS(sha512);

static void *awslc_prov_sha512_newctx(void *provctx) {
(void)provctx;
return awslc_prov_zalloc(awslc_prov_sha512_ctx_size());
}

static void awslc_prov_sha512_freectx(void *dctx) {
awslc_prov_sha2_freectx(dctx, awslc_prov_sha512_ctx_size());
}

static void *awslc_prov_sha512_dupctx(void *dctx) {
return awslc_prov_sha2_dupctx(dctx, awslc_prov_sha512_ctx_size(),
awslc_prov_sha512_copy);
}

static void awslc_prov_sha512_copyctx(void *outctx, void *inctx) {
awslc_prov_sha2_copyctx(outctx, inctx, awslc_prov_sha512_copy);
}

static int awslc_prov_sha512_init_op(void *dctx, const OSSL_PARAM params[]) {
return awslc_prov_sha2_init_op(dctx, params, awslc_prov_sha512_init);
}

static int awslc_prov_sha512_update_op(void *dctx, const unsigned char *in,
size_t inl) {
return awslc_prov_sha2_update_op(dctx, in, inl, awslc_prov_sha512_update);
}

static int awslc_prov_sha512_final_op(void *dctx, unsigned char *out,
size_t *outl, size_t outsz) {
return awslc_prov_sha2_final_op(dctx, out, outl, outsz,
awslc_prov_sha512_final,
awslc_prov_sha512_digest_size());
}

static int awslc_prov_sha512_get_params(OSSL_PARAM params[]) {
return awslc_prov_sha2_get_params(params, awslc_prov_sha512_block_size(),
awslc_prov_sha512_digest_size());
}

AWSLC_PROV_FIXED_DIGEST_DISPATCH_TABLE(sha512);

// SHA-512/224

AWSLC_PROV_DECLARE_FIXED_DIGEST_SLOTS(sha512_224);

static void *awslc_prov_sha512_224_newctx(void *provctx) {
(void)provctx;
return awslc_prov_zalloc(awslc_prov_sha512_224_ctx_size());
}

static void awslc_prov_sha512_224_freectx(void *dctx) {
awslc_prov_sha2_freectx(dctx, awslc_prov_sha512_224_ctx_size());
}

static void *awslc_prov_sha512_224_dupctx(void *dctx) {
return awslc_prov_sha2_dupctx(dctx, awslc_prov_sha512_224_ctx_size(),
awslc_prov_sha512_224_copy);
}

static void awslc_prov_sha512_224_copyctx(void *outctx, void *inctx) {
awslc_prov_sha2_copyctx(outctx, inctx, awslc_prov_sha512_224_copy);
}

static int awslc_prov_sha512_224_init_op(void *dctx,
const OSSL_PARAM params[]) {
return awslc_prov_sha2_init_op(dctx, params, awslc_prov_sha512_224_init);
}

static int awslc_prov_sha512_224_update_op(void *dctx,
const unsigned char *in,
size_t inl) {
return awslc_prov_sha2_update_op(dctx, in, inl,
awslc_prov_sha512_224_update);
}

static int awslc_prov_sha512_224_final_op(void *dctx, unsigned char *out,
size_t *outl, size_t outsz) {
return awslc_prov_sha2_final_op(dctx, out, outl, outsz,
awslc_prov_sha512_224_final,
awslc_prov_sha512_224_digest_size());
}

static int awslc_prov_sha512_224_get_params(OSSL_PARAM params[]) {
return awslc_prov_sha2_get_params(params,
awslc_prov_sha512_224_block_size(),
awslc_prov_sha512_224_digest_size());
}

AWSLC_PROV_FIXED_DIGEST_DISPATCH_TABLE(sha512_224);

// SHA-512/256

AWSLC_PROV_DECLARE_FIXED_DIGEST_SLOTS(sha512_256);

static void *awslc_prov_sha512_256_newctx(void *provctx) {
(void)provctx;
return awslc_prov_zalloc(awslc_prov_sha512_256_ctx_size());
}

static void awslc_prov_sha512_256_freectx(void *dctx) {
awslc_prov_sha2_freectx(dctx, awslc_prov_sha512_256_ctx_size());
}

static void *awslc_prov_sha512_256_dupctx(void *dctx) {
return awslc_prov_sha2_dupctx(dctx, awslc_prov_sha512_256_ctx_size(),
awslc_prov_sha512_256_copy);
}

static void awslc_prov_sha512_256_copyctx(void *outctx, void *inctx) {
awslc_prov_sha2_copyctx(outctx, inctx, awslc_prov_sha512_256_copy);
}

static int awslc_prov_sha512_256_init_op(void *dctx,
const OSSL_PARAM params[]) {
return awslc_prov_sha2_init_op(dctx, params, awslc_prov_sha512_256_init);
}

static int awslc_prov_sha512_256_update_op(void *dctx,
const unsigned char *in,
size_t inl) {
return awslc_prov_sha2_update_op(dctx, in, inl,
awslc_prov_sha512_256_update);
}

static int awslc_prov_sha512_256_final_op(void *dctx, unsigned char *out,
size_t *outl, size_t outsz) {
return awslc_prov_sha2_final_op(dctx, out, outl, outsz,
awslc_prov_sha512_256_final,
awslc_prov_sha512_256_digest_size());
}

static int awslc_prov_sha512_256_get_params(OSSL_PARAM params[]) {
return awslc_prov_sha2_get_params(params,
awslc_prov_sha512_256_block_size(),
awslc_prov_sha512_256_digest_size());
}

AWSLC_PROV_FIXED_DIGEST_DISPATCH_TABLE(sha512_256);
14 changes: 14 additions & 0 deletions provider/frontend/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ static const OSSL_ALGORITHM awslc_prov_digests[] = {
// PROV_NAMES_SHA2_256
AWSLC_PROV_ALG("SHA2-256:SHA-256:SHA256:2.16.840.1.101.3.4.2.1", sha256,
"AWS-LC SHA2-256 implementation"),
// PROV_NAMES_SHA2_384
AWSLC_PROV_ALG("SHA2-384:SHA-384:SHA384:2.16.840.1.101.3.4.2.2", sha384,
"AWS-LC SHA2-384 implementation"),
// PROV_NAMES_SHA2_512
AWSLC_PROV_ALG("SHA2-512:SHA-512:SHA512:2.16.840.1.101.3.4.2.3", sha512,
"AWS-LC SHA2-512 implementation"),
// PROV_NAMES_SHA2_512_224
AWSLC_PROV_ALG(
"SHA2-512/224:SHA-512/224:SHA512-224:2.16.840.1.101.3.4.2.5",
sha512_224, "AWS-LC SHA2-512/224 implementation"),
// PROV_NAMES_SHA2_512_256
AWSLC_PROV_ALG(
"SHA2-512/256:SHA-512/256:SHA512-256:2.16.840.1.101.3.4.2.6",
sha512_256, "AWS-LC SHA2-512/256 implementation"),
{NULL, NULL, NULL, NULL}};

const OSSL_ALGORITHM *awslc_prov_query_operation(void *provctx,
Expand Down
4 changes: 4 additions & 0 deletions provider/internal/backend/digests.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern "C" {
// SHA-2, from backend/operations/digests/sha2.c.
AWSLC_PROV_DECLARE_DIGEST_BACKEND(sha224);
AWSLC_PROV_DECLARE_DIGEST_BACKEND(sha256);
AWSLC_PROV_DECLARE_DIGEST_BACKEND(sha384);
AWSLC_PROV_DECLARE_DIGEST_BACKEND(sha512);
AWSLC_PROV_DECLARE_DIGEST_BACKEND(sha512_224);
AWSLC_PROV_DECLARE_DIGEST_BACKEND(sha512_256);

#if defined(__cplusplus)
} // extern "C"
Expand Down
Loading
Loading