2 * Copyright 2019-2023 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/crypto.h>
11 #include "prov/blake2.h"
12 #include "prov/digestcommon.h"
13 #include "prov/implementations.h"
15 int ossl_blake2s256_init(void *ctx
)
19 ossl_blake2s_param_init(&P
);
20 return ossl_blake2s_init((BLAKE2S_CTX
*)ctx
, &P
);
23 int ossl_blake2b512_init(void *ctx
)
25 struct blake2b_md_data_st
*mdctx
= ctx
;
27 ossl_blake2b_param_init(&mdctx
->params
);
28 return ossl_blake2b_init(&mdctx
->ctx
, &mdctx
->params
);
31 /* ossl_blake2s256_functions */
32 IMPLEMENT_digest_functions(blake2s256
, BLAKE2S_CTX
,
33 BLAKE2S_BLOCKBYTES
, BLAKE2S_DIGEST_LENGTH
, 0,
34 ossl_blake2s256_init
, ossl_blake2s_update
,
37 /* ossl_blake2b512_functions */
39 static OSSL_FUNC_digest_init_fn blake2b512_internal_init
;
40 static OSSL_FUNC_digest_newctx_fn blake2b512_newctx
;
41 static OSSL_FUNC_digest_freectx_fn blake2b512_freectx
;
42 static OSSL_FUNC_digest_dupctx_fn blake2b512_dupctx
;
43 static OSSL_FUNC_digest_final_fn blake2b512_internal_final
;
44 static OSSL_FUNC_digest_get_params_fn blake2b512_get_params
;
46 static int blake2b512_internal_init(void *ctx
, const OSSL_PARAM params
[])
48 return ossl_prov_is_running() && ossl_blake2b_set_ctx_params(ctx
, params
)
49 && ossl_blake2b512_init(ctx
);
52 static void *blake2b512_newctx(void *prov_ctx
)
54 struct blake2b_md_data_st
*ctx
;
56 ctx
= ossl_prov_is_running() ? OPENSSL_zalloc(sizeof(*ctx
)) : NULL
;
60 static void blake2b512_freectx(void *vctx
)
62 struct blake2b_md_data_st
*ctx
;
64 ctx
= (struct blake2b_md_data_st
*)vctx
;
65 OPENSSL_clear_free(ctx
, sizeof(*ctx
));
68 static void *blake2b512_dupctx(void *ctx
)
70 struct blake2b_md_data_st
*in
, *ret
;
72 in
= (struct blake2b_md_data_st
*)ctx
;
73 ret
= ossl_prov_is_running()? OPENSSL_malloc(sizeof(*ret
)) : NULL
;
79 static int blake2b512_internal_final(void *ctx
, unsigned char *out
,
80 size_t *outl
, size_t outsz
)
82 struct blake2b_md_data_st
*b_ctx
;
84 b_ctx
= (struct blake2b_md_data_st
*)ctx
;
85 *outl
= b_ctx
->ctx
.outlen
;
87 if (!ossl_prov_is_running())
90 return (outsz
> 0) ? ossl_blake2b_final(out
, ctx
) : 1;
93 static int blake2b512_get_params(OSSL_PARAM params
[])
95 return ossl_digest_default_get_params(params
, BLAKE2B_BLOCKBYTES
, 64, 0);
98 const OSSL_DISPATCH ossl_blake2b512_functions
[] =
99 { {OSSL_FUNC_DIGEST_NEWCTX
, (void (*)(void))blake2b512_newctx
},
100 {OSSL_FUNC_DIGEST_UPDATE
, (void (*)(void))ossl_blake2b_update
},
101 {OSSL_FUNC_DIGEST_FINAL
, (void (*)(void))blake2b512_internal_final
},
102 {OSSL_FUNC_DIGEST_FREECTX
, (void (*)(void))blake2b512_freectx
},
103 {OSSL_FUNC_DIGEST_DUPCTX
, (void (*)(void))blake2b512_dupctx
},
104 {OSSL_FUNC_DIGEST_GET_PARAMS
, (void (*)(void))blake2b512_get_params
},
105 {OSSL_FUNC_DIGEST_GETTABLE_PARAMS
,
106 (void (*)(void))ossl_digest_default_gettable_params
},
107 {OSSL_FUNC_DIGEST_INIT
, (void (*)(void))blake2b512_internal_init
},
108 {OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS
,
109 (void (*)(void))ossl_blake2b_settable_ctx_params
},
110 {OSSL_FUNC_DIGEST_SET_CTX_PARAMS
,
111 (void (*)(void))ossl_blake2b_set_ctx_params
}, {0, NULL
} };