23 #include <crypto/sha.h>
24 #include <linux/module.h>
39 memset(sctx, 0,
sizeof *sctx);
46 nx_ctx->
op.outlen = (nx_ctx->
out_sg - out_sg) *
sizeof(
struct nx_sg);
58 u64 to_process, leftover, spbc_bits;
64 memcpy(csbcpb->
cpb.sha512.input_partial_digest,
74 sctx->
count[0] += len;
85 sctx->
count[0], nx_ctx->
ap->sglen);
87 to_process - sctx->
count[0],
89 nx_ctx->
op.inlen = (nx_ctx->
in_sg - in_sg) *
93 to_process, nx_ctx->
ap->sglen);
94 nx_ctx->
op.inlen = (nx_ctx->
in_sg - in_sg) *
100 if (!nx_ctx->
op.inlen || !nx_ctx->
op.outlen) {
113 memcpy(sctx->
buf, data + len - leftover, leftover);
114 sctx->
count[0] = leftover;
116 spbc_bits = csbcpb->
cpb.sha512.spbc * 8;
117 csbcpb->
cpb.sha512.message_bit_length_lo += spbc_bits;
118 if (csbcpb->
cpb.sha512.message_bit_length_lo < spbc_bits)
119 csbcpb->
cpb.sha512.message_bit_length_hi++;
132 struct nx_sg *in_sg, *out_sg;
139 memcpy(csbcpb->
cpb.sha512.input_partial_digest,
147 count0 = sctx->
count[0] * 8;
149 csbcpb->
cpb.sha512.message_bit_length_lo += count0;
150 if (csbcpb->
cpb.sha512.message_bit_length_lo < count0)
151 csbcpb->
cpb.sha512.message_bit_length_hi++;
157 nx_ctx->
op.inlen = (nx_ctx->
in_sg - in_sg) *
sizeof(
struct nx_sg);
158 nx_ctx->
op.outlen = (nx_ctx->
out_sg - out_sg) *
sizeof(
struct nx_sg);
160 if (!nx_ctx->
op.outlen) {
172 &(nx_ctx->
stats->sha512_bytes));
179 static int nx_sha512_export(
struct shash_desc *desc,
void *out)
188 octx->
count[0] = csbcpb->
cpb.sha512.message_bit_length_lo >> 3 |
189 ((csbcpb->
cpb.sha512.message_bit_length_hi & 7) << 61);
190 octx->count[1] = csbcpb->
cpb.sha512.message_bit_length_hi >> 3;
192 octx->count[0] += sctx->
count[0];
193 if (octx->count[0] < sctx->
count[0])
196 memcpy(octx->buf, sctx->
buf,
sizeof(octx->buf));
201 if (csbcpb->
cpb.sha512.message_bit_length_hi ||
202 csbcpb->
cpb.sha512.message_bit_length_lo)
203 memcpy(octx->state, csbcpb->
cpb.sha512.message_digest,
219 static int nx_sha512_import(
struct shash_desc *desc,
const void *
in)
226 memcpy(sctx->
buf, ictx->buf,
sizeof(ictx->buf));
227 sctx->
count[0] = ictx->count[0] & 0x3f;
228 csbcpb->
cpb.sha512.message_bit_length_lo = (ictx->count[0] & ~0x3f)
230 csbcpb->
cpb.sha512.message_bit_length_hi = ictx->count[1] << 3 |
231 ictx->count[0] >> 61;
233 if (csbcpb->
cpb.sha512.message_bit_length_hi ||
234 csbcpb->
cpb.sha512.message_bit_length_lo) {
235 memcpy(csbcpb->
cpb.sha512.message_digest, ictx->state,
247 .init = nx_sha512_init,
248 .update = nx_sha512_update,
249 .final = nx_sha512_final,
250 .export = nx_sha512_export,
251 .import = nx_sha512_import,
255 .cra_name =
"sha512",
256 .cra_driver_name =
"sha512-nx",