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