2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/sha.h>
11 #include <openssl/crypto.h>
12 #include <openssl/core_numbers.h>
14 static int sha256_final(void *ctx, unsigned char *md, size_t *size)
16 if (SHA256_Final(md, ctx)) {
17 *size = SHA256_DIGEST_LENGTH;
24 static void *sha256_newctx(void)
26 SHA256_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
31 static void sha256_freectx(void *vctx)
33 SHA256_CTX *ctx = (SHA256_CTX *)vctx;
35 OPENSSL_clear_free(ctx, sizeof(*ctx));
38 static void *sha256_dupctx(void *ctx)
40 SHA256_CTX *in = (SHA256_CTX *)ctx;
41 SHA256_CTX *ret = OPENSSL_malloc(sizeof(*ret));
48 static size_t sha256_size(void)
50 return SHA256_DIGEST_LENGTH;
53 static size_t sha256_block_size(void)
58 extern const OSSL_DISPATCH sha256_functions[];
59 const OSSL_DISPATCH sha256_functions[] = {
60 { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))sha256_newctx },
61 { OSSL_FUNC_DIGEST_INIT, (void (*)(void))SHA256_Init },
62 { OSSL_FUNC_DIGEST_UPDDATE, (void (*)(void))SHA256_Update },
63 { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))sha256_final },
64 { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))sha256_freectx },
65 { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))sha256_dupctx },
66 { OSSL_FUNC_DIGEST_SIZE, (void (*)(void))sha256_size },
67 { OSSL_FUNC_DIGEST_BLOCK_SIZE, (void (*)(void))sha256_block_size },