Fix Blake block length
[openssl.git] / crypto / blake2 / m_blake2s.c
1 /*
2  * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.
3  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4  *
5  * Licensed under the OpenSSL licenses (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * https://www.openssl.org/source/license.html
9  * or in the file LICENSE in the source distribution.
10  */
11
12 /*
13  * Derived from the BLAKE2 reference implementation written by Samuel Neves.
14  * More information about the BLAKE2 hash function and its implementations
15  * can be found at https://blake2.net.
16  */
17
18 #include "internal/cryptlib.h"
19
20 #ifndef OPENSSL_NO_BLAKE2
21
22 # include <openssl/evp.h>
23 # include <openssl/objects.h>
24 # include "blake2_locl.h"
25 # include "internal/evp_int.h"
26
27 static int init(EVP_MD_CTX *ctx)
28 {
29     return BLAKE2s_Init(EVP_MD_CTX_md_data(ctx));
30 }
31
32 static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
33 {
34     return BLAKE2s_Update(EVP_MD_CTX_md_data(ctx), data, count);
35 }
36
37 static int final(EVP_MD_CTX *ctx, unsigned char *md)
38 {
39     return BLAKE2s_Final(md, EVP_MD_CTX_md_data(ctx));
40 }
41
42 static const EVP_MD blake2s_md = {
43     NID_blake2s256,
44     0,
45     BLAKE2S_DIGEST_LENGTH,
46     0,
47     init,
48     update,
49     final,
50     NULL,
51     NULL,
52     BLAKE2S_BLOCKBYTES,
53     sizeof(EVP_MD *) + sizeof(BLAKE2S_CTX),
54 };
55
56 const EVP_MD *EVP_blake2s256(void)
57 {
58     return (&blake2s_md);
59 }
60 #endif