1 /* This file is in the public domain. */
4 #include <contrib/libb2/blake2.h>
5 #include <opencrypto/xform_auth.h>
7 extern int blake2b_init_ref(blake2b_state *S, size_t outlen);
8 extern int blake2b_init_param_ref(blake2b_state *S, const blake2b_param *P);
9 extern int blake2b_init_key_ref(blake2b_state *S, size_t outlen,
10 const void *key, size_t keylen);
11 extern int blake2b_update_ref(blake2b_state *S, const uint8_t *in,
13 extern int blake2b_final_ref(blake2b_state *S, uint8_t *out, size_t outlen);
14 extern int blake2b_ref(uint8_t *out, const void *in, const void *key,
15 size_t outlen, size_t inlen, size_t keylen);
17 extern int blake2s_init_ref(blake2s_state *S, size_t outlen);
18 extern int blake2s_init_param_ref(blake2s_state *S, const blake2s_param *P);
19 extern int blake2s_init_key_ref(blake2s_state *S, size_t outlen,
20 const void *key, size_t keylen);
21 extern int blake2s_update_ref(blake2s_state *S, const uint8_t *in,
23 extern int blake2s_final_ref(blake2s_state *S, uint8_t *out, size_t outlen);
24 extern int blake2s_ref(uint8_t *out, const void *in, const void *key,
25 size_t outlen, size_t inlen, size_t keylen);
27 struct blake2b_xform_ctx {
30 CTASSERT(sizeof(union authctx) >= sizeof(struct blake2b_xform_ctx));
33 blake2b_xform_init(void *vctx)
35 struct blake2b_xform_ctx *ctx = vctx;
38 rc = blake2b_init_ref(&ctx->state, BLAKE2B_OUTBYTES);
40 panic("blake2b_init: invalid arguments");
44 blake2b_xform_setkey(void *vctx, const uint8_t *key, u_int klen)
46 struct blake2b_xform_ctx *ctx = vctx;
49 rc = blake2b_init_key_ref(&ctx->state, BLAKE2B_OUTBYTES, key,
52 panic("blake2b_init_key: invalid arguments");
56 blake2b_xform_update(void *vctx, const void *data, u_int len)
58 struct blake2b_xform_ctx *ctx = vctx;
61 rc = blake2b_update_ref(&ctx->state, data, len);
68 blake2b_xform_final(uint8_t *out, void *vctx)
70 struct blake2b_xform_ctx *ctx = vctx;
73 rc = blake2b_final_ref(&ctx->state, out, BLAKE2B_OUTBYTES);
75 panic("blake2b_final: invalid");
78 const struct auth_hash auth_hash_blake2b = {
79 .type = CRYPTO_BLAKE2B,
81 .keysize = BLAKE2B_KEYBYTES,
82 .hashsize = BLAKE2B_OUTBYTES,
83 .ctxsize = sizeof(struct blake2b_xform_ctx),
84 .Setkey = blake2b_xform_setkey,
85 .Init = blake2b_xform_init,
86 .Update = blake2b_xform_update,
87 .Final = blake2b_xform_final,
90 struct blake2s_xform_ctx {
93 CTASSERT(sizeof(union authctx) >= sizeof(struct blake2s_xform_ctx));
96 blake2s_xform_init(void *vctx)
98 struct blake2s_xform_ctx *ctx = vctx;
101 rc = blake2s_init_ref(&ctx->state, BLAKE2S_OUTBYTES);
103 panic("blake2s_init: invalid arguments");
107 blake2s_xform_setkey(void *vctx, const uint8_t *key, u_int klen)
109 struct blake2s_xform_ctx *ctx = vctx;
112 rc = blake2s_init_key_ref(&ctx->state, BLAKE2S_OUTBYTES, key,
115 panic("blake2s_init_key: invalid arguments");
119 blake2s_xform_update(void *vctx, const void *data, u_int len)
121 struct blake2s_xform_ctx *ctx = vctx;
124 rc = blake2s_update_ref(&ctx->state, data, len);
131 blake2s_xform_final(uint8_t *out, void *vctx)
133 struct blake2s_xform_ctx *ctx = vctx;
136 rc = blake2s_final_ref(&ctx->state, out, BLAKE2S_OUTBYTES);
138 panic("blake2s_final: invalid");
141 const struct auth_hash auth_hash_blake2s = {
142 .type = CRYPTO_BLAKE2S,
144 .keysize = BLAKE2S_KEYBYTES,
145 .hashsize = BLAKE2S_OUTBYTES,
146 .ctxsize = sizeof(struct blake2s_xform_ctx),
147 .Setkey = blake2s_xform_setkey,
148 .Init = blake2s_xform_init,
149 .Update = blake2s_xform_update,
150 .Final = blake2s_xform_final,