Thomas Gleixner | 64d85cc | 2019-05-29 07:18:13 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 2 | /** |
| 3 | * SHA-256 routines supporting the Power 7+ Nest Accelerators driver |
| 4 | * |
| 5 | * Copyright (C) 2011-2012 International Business Machines Inc. |
| 6 | * |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 7 | * Author: Kent Yoder <yoder1@us.ibm.com> |
| 8 | */ |
| 9 | |
| 10 | #include <crypto/internal/hash.h> |
| 11 | #include <crypto/sha.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <asm/vio.h> |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 14 | #include <asm/byteorder.h> |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 15 | |
| 16 | #include "nx_csbcpb.h" |
| 17 | #include "nx.h" |
| 18 | |
| 19 | |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 20 | static int nx_crypto_ctx_sha256_init(struct crypto_tfm *tfm) |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 21 | { |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 22 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); |
| 23 | int err; |
| 24 | |
| 25 | err = nx_crypto_ctx_sha_init(tfm); |
| 26 | if (err) |
| 27 | return err; |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 28 | |
| 29 | nx_ctx_init(nx_ctx, HCOP_FC_SHA); |
| 30 | |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 31 | nx_ctx->ap = &nx_ctx->props[NX_PROPS_SHA256]; |
| 32 | |
| 33 | NX_CPB_SET_DIGEST_SIZE(nx_ctx->csbcpb, NX_DS_SHA256); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 34 | |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 35 | return 0; |
| 36 | } |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 37 | |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 38 | static int nx_sha256_init(struct shash_desc *desc) { |
| 39 | struct sha256_state *sctx = shash_desc_ctx(desc); |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 40 | |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 41 | memset(sctx, 0, sizeof *sctx); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 42 | |
| 43 | sctx->state[0] = __cpu_to_be32(SHA256_H0); |
| 44 | sctx->state[1] = __cpu_to_be32(SHA256_H1); |
| 45 | sctx->state[2] = __cpu_to_be32(SHA256_H2); |
| 46 | sctx->state[3] = __cpu_to_be32(SHA256_H3); |
| 47 | sctx->state[4] = __cpu_to_be32(SHA256_H4); |
| 48 | sctx->state[5] = __cpu_to_be32(SHA256_H5); |
| 49 | sctx->state[6] = __cpu_to_be32(SHA256_H6); |
| 50 | sctx->state[7] = __cpu_to_be32(SHA256_H7); |
| 51 | sctx->count = 0; |
| 52 | |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int nx_sha256_update(struct shash_desc *desc, const u8 *data, |
| 57 | unsigned int len) |
| 58 | { |
| 59 | struct sha256_state *sctx = shash_desc_ctx(desc); |
| 60 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); |
| 61 | struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb; |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 62 | struct nx_sg *out_sg; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 63 | u64 to_process = 0, leftover, total; |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 64 | unsigned long irq_flags; |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 65 | int rc = 0; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 66 | int data_len; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 67 | u32 max_sg_len; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 68 | u64 buf_len = (sctx->count % SHA256_BLOCK_SIZE); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 69 | |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 70 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
| 71 | |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 72 | /* 2 cases for total data len: |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 73 | * 1: < SHA256_BLOCK_SIZE: copy into state, return 0 |
| 74 | * 2: >= SHA256_BLOCK_SIZE: process X blocks, copy in leftover |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 75 | */ |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 76 | total = (sctx->count % SHA256_BLOCK_SIZE) + len; |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 77 | if (total < SHA256_BLOCK_SIZE) { |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 78 | memcpy(sctx->buf + buf_len, data, len); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 79 | sctx->count += len; |
| 80 | goto out; |
| 81 | } |
| 82 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 83 | memcpy(csbcpb->cpb.sha256.message_digest, sctx->state, SHA256_DIGEST_SIZE); |
| 84 | NX_CPB_FDM(csbcpb) |= NX_FDM_INTERMEDIATE; |
| 85 | NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION; |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 86 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 87 | max_sg_len = min_t(u64, nx_ctx->ap->sglen, |
| 88 | nx_driver.of.max_sg_len/sizeof(struct nx_sg)); |
| 89 | max_sg_len = min_t(u64, max_sg_len, |
| 90 | nx_ctx->ap->databytelen/NX_PAGE_SIZE); |
| 91 | |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 92 | data_len = SHA256_DIGEST_SIZE; |
| 93 | out_sg = nx_build_sg_list(nx_ctx->out_sg, (u8 *)sctx->state, |
| 94 | &data_len, max_sg_len); |
| 95 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); |
| 96 | |
| 97 | if (data_len != SHA256_DIGEST_SIZE) { |
| 98 | rc = -EINVAL; |
| 99 | goto out; |
| 100 | } |
| 101 | |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 102 | do { |
Jan Stancek | d3392f41 | 2015-08-08 08:47:28 +0200 | [diff] [blame] | 103 | int used_sgs = 0; |
| 104 | struct nx_sg *in_sg = nx_ctx->in_sg; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 105 | |
| 106 | if (buf_len) { |
| 107 | data_len = buf_len; |
Jan Stancek | d3392f41 | 2015-08-08 08:47:28 +0200 | [diff] [blame] | 108 | in_sg = nx_build_sg_list(in_sg, |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 109 | (u8 *) sctx->buf, |
| 110 | &data_len, |
| 111 | max_sg_len); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 112 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 113 | if (data_len != buf_len) { |
| 114 | rc = -EINVAL; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 115 | goto out; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 116 | } |
Jan Stancek | d3392f41 | 2015-08-08 08:47:28 +0200 | [diff] [blame] | 117 | used_sgs = in_sg - nx_ctx->in_sg; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 118 | } |
| 119 | |
Jan Stancek | d3392f41 | 2015-08-08 08:47:28 +0200 | [diff] [blame] | 120 | /* to_process: SHA256_BLOCK_SIZE aligned chunk to be |
| 121 | * processed in this iteration. This value is restricted |
| 122 | * by sg list limits and number of sgs we already used |
| 123 | * for leftover data. (see above) |
| 124 | * In ideal case, we could allow NX_PAGE_SIZE * max_sg_len, |
| 125 | * but because data may not be aligned, we need to account |
| 126 | * for that too. */ |
| 127 | to_process = min_t(u64, total, |
| 128 | (max_sg_len - 1 - used_sgs) * NX_PAGE_SIZE); |
| 129 | to_process = to_process & ~(SHA256_BLOCK_SIZE - 1); |
| 130 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 131 | data_len = to_process - buf_len; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 132 | in_sg = nx_build_sg_list(in_sg, (u8 *) data, |
| 133 | &data_len, max_sg_len); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 134 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 135 | nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * sizeof(struct nx_sg); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 136 | |
Jan Stancek | d3392f41 | 2015-08-08 08:47:28 +0200 | [diff] [blame] | 137 | to_process = data_len + buf_len; |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 138 | leftover = total - to_process; |
| 139 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 140 | /* |
| 141 | * we've hit the nx chip previously and we're updating |
| 142 | * again, so copy over the partial digest. |
| 143 | */ |
| 144 | memcpy(csbcpb->cpb.sha256.input_partial_digest, |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 145 | csbcpb->cpb.sha256.message_digest, |
| 146 | SHA256_DIGEST_SIZE); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 147 | |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 148 | if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) { |
| 149 | rc = -EINVAL; |
| 150 | goto out; |
| 151 | } |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 152 | |
Eric Biggers | 75f2222 | 2019-04-14 17:37:08 -0700 | [diff] [blame] | 153 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, 0); |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 154 | if (rc) |
| 155 | goto out; |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 156 | |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 157 | atomic_inc(&(nx_ctx->stats->sha256_ops)); |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 158 | |
| 159 | total -= to_process; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 160 | data += to_process - buf_len; |
| 161 | buf_len = 0; |
| 162 | |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 163 | } while (leftover >= SHA256_BLOCK_SIZE); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 164 | |
| 165 | /* copy the leftover back into the state struct */ |
Kent Yoder | 1ad936e | 2013-04-12 17:13:59 +0000 | [diff] [blame] | 166 | if (leftover) |
Marcelo Cerri | d311149 | 2013-08-02 12:09:52 +0000 | [diff] [blame] | 167 | memcpy(sctx->buf, data, leftover); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 168 | |
| 169 | sctx->count += len; |
| 170 | memcpy(sctx->state, csbcpb->cpb.sha256.message_digest, SHA256_DIGEST_SIZE); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 171 | out: |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 172 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 173 | return rc; |
| 174 | } |
| 175 | |
| 176 | static int nx_sha256_final(struct shash_desc *desc, u8 *out) |
| 177 | { |
| 178 | struct sha256_state *sctx = shash_desc_ctx(desc); |
| 179 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); |
| 180 | struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 181 | struct nx_sg *in_sg, *out_sg; |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 182 | unsigned long irq_flags; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 183 | u32 max_sg_len; |
| 184 | int rc = 0; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 185 | int len; |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 186 | |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 187 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
| 188 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 189 | max_sg_len = min_t(u64, nx_ctx->ap->sglen, |
| 190 | nx_driver.of.max_sg_len/sizeof(struct nx_sg)); |
| 191 | max_sg_len = min_t(u64, max_sg_len, |
| 192 | nx_ctx->ap->databytelen/NX_PAGE_SIZE); |
| 193 | |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 194 | /* final is represented by continuing the operation and indicating that |
| 195 | * this is not an intermediate operation */ |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 196 | if (sctx->count >= SHA256_BLOCK_SIZE) { |
| 197 | /* we've hit the nx chip previously, now we're finalizing, |
| 198 | * so copy over the partial digest */ |
| 199 | memcpy(csbcpb->cpb.sha256.input_partial_digest, sctx->state, SHA256_DIGEST_SIZE); |
| 200 | NX_CPB_FDM(csbcpb) &= ~NX_FDM_INTERMEDIATE; |
| 201 | NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION; |
| 202 | } else { |
| 203 | NX_CPB_FDM(csbcpb) &= ~NX_FDM_INTERMEDIATE; |
| 204 | NX_CPB_FDM(csbcpb) &= ~NX_FDM_CONTINUATION; |
| 205 | } |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 206 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 207 | csbcpb->cpb.sha256.message_bit_length = (u64) (sctx->count * 8); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 208 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 209 | len = sctx->count & (SHA256_BLOCK_SIZE - 1); |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 210 | in_sg = nx_build_sg_list(nx_ctx->in_sg, (u8 *) sctx->buf, |
| 211 | &len, max_sg_len); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 212 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 213 | if (len != (sctx->count & (SHA256_BLOCK_SIZE - 1))) { |
| 214 | rc = -EINVAL; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 215 | goto out; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 216 | } |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 217 | |
| 218 | len = SHA256_DIGEST_SIZE; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 219 | out_sg = nx_build_sg_list(nx_ctx->out_sg, out, &len, max_sg_len); |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 220 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 221 | if (len != SHA256_DIGEST_SIZE) { |
| 222 | rc = -EINVAL; |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 223 | goto out; |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 224 | } |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 225 | |
Leonidas Da Silva Barbosa | 10d87b7 | 2015-04-23 17:41:43 -0300 | [diff] [blame] | 226 | nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * sizeof(struct nx_sg); |
| 227 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 228 | if (!nx_ctx->op.outlen) { |
| 229 | rc = -EINVAL; |
| 230 | goto out; |
| 231 | } |
| 232 | |
Eric Biggers | 75f2222 | 2019-04-14 17:37:08 -0700 | [diff] [blame] | 233 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, 0); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 234 | if (rc) |
| 235 | goto out; |
| 236 | |
| 237 | atomic_inc(&(nx_ctx->stats->sha256_ops)); |
| 238 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 239 | atomic64_add(sctx->count, &(nx_ctx->stats->sha256_bytes)); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 240 | memcpy(out, csbcpb->cpb.sha256.message_digest, SHA256_DIGEST_SIZE); |
| 241 | out: |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 242 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 243 | return rc; |
| 244 | } |
| 245 | |
| 246 | static int nx_sha256_export(struct shash_desc *desc, void *out) |
| 247 | { |
| 248 | struct sha256_state *sctx = shash_desc_ctx(desc); |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 249 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 250 | memcpy(out, sctx, sizeof(*sctx)); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 251 | |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int nx_sha256_import(struct shash_desc *desc, const void *in) |
| 256 | { |
| 257 | struct sha256_state *sctx = shash_desc_ctx(desc); |
Marcelo Cerri | c849163 | 2013-08-12 18:49:37 -0300 | [diff] [blame] | 258 | |
Leonidas S. Barbosa | 0008511 | 2014-10-28 15:49:46 -0200 | [diff] [blame] | 259 | memcpy(sctx, in, sizeof(*sctx)); |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 260 | |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | struct shash_alg nx_shash_sha256_alg = { |
| 265 | .digestsize = SHA256_DIGEST_SIZE, |
| 266 | .init = nx_sha256_init, |
| 267 | .update = nx_sha256_update, |
| 268 | .final = nx_sha256_final, |
| 269 | .export = nx_sha256_export, |
| 270 | .import = nx_sha256_import, |
| 271 | .descsize = sizeof(struct sha256_state), |
| 272 | .statesize = sizeof(struct sha256_state), |
| 273 | .base = { |
| 274 | .cra_name = "sha256", |
| 275 | .cra_driver_name = "sha256-nx", |
| 276 | .cra_priority = 300, |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 277 | .cra_blocksize = SHA256_BLOCK_SIZE, |
| 278 | .cra_module = THIS_MODULE, |
| 279 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), |
Herbert Xu | 030f4e9 | 2015-07-07 17:30:25 +0800 | [diff] [blame] | 280 | .cra_init = nx_crypto_ctx_sha256_init, |
Kent Yoder | 528e396 | 2012-05-14 11:06:20 +0000 | [diff] [blame] | 281 | .cra_exit = nx_crypto_ctx_exit, |
| 282 | } |
| 283 | }; |