511b192c1d646da0a9a2b9f25c9617ecca110949
[openssl.git] / crypto / evp / m_blake2s.c
1 /*
2  * BLAKE2 reference source code package - reference C implementations
3  *
4  * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.
5  * You may use this under the terms of the CC0, the OpenSSL Licence, or the
6  * Apache Public License 2.0, at your option.  The terms of these licenses can
7  * be found at:
8  *
9  * - OpenSSL license   : https://www.openssl.org/source/license.html
10  * - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
11  * - CC0 1.0 Universal : http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * More information about the BLAKE2 hash function can be found at
14  * https://blake2.net.
15  */
16
17 /* crypto/evp/m_blake2s.c */
18
19 #include <stdio.h>
20 #include "internal/cryptlib.h"
21
22 #ifndef OPENSSL_NO_BLAKE2
23
24 # include <openssl/evp.h>
25 # include <openssl/objects.h>
26 # include "internal/blake2_locl.h"
27 # include "internal/evp_int.h"
28
29 static int init(EVP_MD_CTX *ctx)
30 {
31     return BLAKE2s_Init(EVP_MD_CTX_md_data(ctx));
32 }
33
34 static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
35 {
36     return BLAKE2s_Update(EVP_MD_CTX_md_data(ctx), data, count);
37 }
38
39 static int final(EVP_MD_CTX *ctx, unsigned char *md)
40 {
41     return BLAKE2s_Final(md, EVP_MD_CTX_md_data(ctx));
42 }
43
44 static const EVP_MD blake2s_md = {
45     NID_blake2s,
46     0,
47     BLAKE2S_DIGEST_LENGTH,
48     0,
49     init,
50     update,
51     final,
52     NULL,
53     NULL,
54     0,
55     sizeof(EVP_MD *) + sizeof(BLAKE2S_CTX),
56 };
57
58 const EVP_MD *EVP_blake2s(void)
59 {
60     return (&blake2s_md);
61 }
62 #endif