xref: /openssl/crypto/evp/legacy_blake2.c (revision 556009c5)
1 /*
2  * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9 
10 #include "crypto/evp.h"
11 #include "prov/blake2.h"        /* diverse BLAKE2 macros */
12 #include "legacy_meth.h"
13 
14 /*
15  * Local hack to adapt the BLAKE2 init functions to what the
16  * legacy function signatures demand.
17  */
blake2s_init(BLAKE2S_CTX * C)18 static int blake2s_init(BLAKE2S_CTX *C)
19 {
20     BLAKE2S_PARAM P;
21 
22     ossl_blake2s_param_init(&P);
23     return ossl_blake2s_init(C, &P);
24 }
blake2b_init(BLAKE2B_CTX * C)25 static int blake2b_init(BLAKE2B_CTX *C)
26 {
27     BLAKE2B_PARAM P;
28 
29     ossl_blake2b_param_init(&P);
30     return ossl_blake2b_init(C, &P);
31 }
32 #define blake2s_update ossl_blake2s_update
33 #define blake2b_update ossl_blake2b_update
34 #define blake2s_final ossl_blake2s_final
35 #define blake2b_final ossl_blake2b_final
36 
37 IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2s_int, blake2s)
38 IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2b_int, blake2b)
39 
40 static const EVP_MD blake2b_md = {
41     NID_blake2b512,
42     0,
43     BLAKE2B_DIGEST_LENGTH,
44     0,
45     EVP_ORIG_GLOBAL,
46     LEGACY_EVP_MD_METH_TABLE(blake2b_int_init, blake2b_int_update,
47                              blake2b_int_final, NULL, BLAKE2B_BLOCKBYTES),
48 };
49 
EVP_blake2b512(void)50 const EVP_MD *EVP_blake2b512(void)
51 {
52     return &blake2b_md;
53 }
54 
55 static const EVP_MD blake2s_md = {
56     NID_blake2s256,
57     0,
58     BLAKE2S_DIGEST_LENGTH,
59     0,
60     EVP_ORIG_GLOBAL,
61     LEGACY_EVP_MD_METH_TABLE(blake2s_int_init, blake2s_int_update,
62                              blake2s_int_final, NULL, BLAKE2S_BLOCKBYTES),
63 };
64 
EVP_blake2s256(void)65 const EVP_MD *EVP_blake2s256(void)
66 {
67     return &blake2s_md;
68 }
69