~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/mips/cavium-octeon/crypto/octeon-md5.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/mips/cavium-octeon/crypto/octeon-md5.c (Architecture ppc) and /arch/mips/cavium-octeon/crypto/octeon-md5.c (Architecture mips)


  1 /*                                                  1 /*
  2  * Cryptographic API.                               2  * Cryptographic API.
  3  *                                                  3  *
  4  * MD5 Message Digest Algorithm (RFC1321).          4  * MD5 Message Digest Algorithm (RFC1321).
  5  *                                                  5  *
  6  * Adapted for OCTEON by Aaro Koskinen <aaro.k      6  * Adapted for OCTEON by Aaro Koskinen <aaro.koskinen@iki.fi>.
  7  *                                                  7  *
  8  * Based on crypto/md5.c, which is:                 8  * Based on crypto/md5.c, which is:
  9  *                                                  9  *
 10  * Derived from cryptoapi implementation, orig     10  * Derived from cryptoapi implementation, originally based on the
 11  * public domain implementation written by Col     11  * public domain implementation written by Colin Plumb in 1993.
 12  *                                                 12  *
 13  * Copyright (c) Cryptoapi developers.             13  * Copyright (c) Cryptoapi developers.
 14  * Copyright (c) 2002 James Morris <jmorris@in     14  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
 15  *                                                 15  *
 16  * This program is free software; you can redi     16  * This program is free software; you can redistribute it and/or modify it
 17  * under the terms of the GNU General Public L     17  * under the terms of the GNU General Public License as published by the Free
 18  * Software Foundation; either version 2 of th     18  * Software Foundation; either version 2 of the License, or (at your option)
 19  * any later version.                              19  * any later version.
 20  */                                                20  */
 21                                                    21 
 22 #include <crypto/md5.h>                            22 #include <crypto/md5.h>
 23 #include <linux/init.h>                            23 #include <linux/init.h>
 24 #include <linux/types.h>                           24 #include <linux/types.h>
 25 #include <linux/module.h>                          25 #include <linux/module.h>
 26 #include <linux/string.h>                          26 #include <linux/string.h>
 27 #include <asm/byteorder.h>                         27 #include <asm/byteorder.h>
 28 #include <asm/octeon/octeon.h>                     28 #include <asm/octeon/octeon.h>
 29 #include <crypto/internal/hash.h>                  29 #include <crypto/internal/hash.h>
 30                                                    30 
 31 #include "octeon-crypto.h"                         31 #include "octeon-crypto.h"
 32                                                    32 
 33 /*                                                 33 /*
 34  * We pass everything as 64-bit. OCTEON can ha     34  * We pass everything as 64-bit. OCTEON can handle misaligned data.
 35  */                                                35  */
 36                                                    36 
 37 static void octeon_md5_store_hash(struct md5_s     37 static void octeon_md5_store_hash(struct md5_state *ctx)
 38 {                                                  38 {
 39         u64 *hash = (u64 *)ctx->hash;              39         u64 *hash = (u64 *)ctx->hash;
 40                                                    40 
 41         write_octeon_64bit_hash_dword(hash[0],     41         write_octeon_64bit_hash_dword(hash[0], 0);
 42         write_octeon_64bit_hash_dword(hash[1],     42         write_octeon_64bit_hash_dword(hash[1], 1);
 43 }                                                  43 }
 44                                                    44 
 45 static void octeon_md5_read_hash(struct md5_st     45 static void octeon_md5_read_hash(struct md5_state *ctx)
 46 {                                                  46 {
 47         u64 *hash = (u64 *)ctx->hash;              47         u64 *hash = (u64 *)ctx->hash;
 48                                                    48 
 49         hash[0] = read_octeon_64bit_hash_dword     49         hash[0] = read_octeon_64bit_hash_dword(0);
 50         hash[1] = read_octeon_64bit_hash_dword     50         hash[1] = read_octeon_64bit_hash_dword(1);
 51 }                                                  51 }
 52                                                    52 
 53 static void octeon_md5_transform(const void *_     53 static void octeon_md5_transform(const void *_block)
 54 {                                                  54 {
 55         const u64 *block = _block;                 55         const u64 *block = _block;
 56                                                    56 
 57         write_octeon_64bit_block_dword(block[0     57         write_octeon_64bit_block_dword(block[0], 0);
 58         write_octeon_64bit_block_dword(block[1     58         write_octeon_64bit_block_dword(block[1], 1);
 59         write_octeon_64bit_block_dword(block[2     59         write_octeon_64bit_block_dword(block[2], 2);
 60         write_octeon_64bit_block_dword(block[3     60         write_octeon_64bit_block_dword(block[3], 3);
 61         write_octeon_64bit_block_dword(block[4     61         write_octeon_64bit_block_dword(block[4], 4);
 62         write_octeon_64bit_block_dword(block[5     62         write_octeon_64bit_block_dword(block[5], 5);
 63         write_octeon_64bit_block_dword(block[6     63         write_octeon_64bit_block_dword(block[6], 6);
 64         octeon_md5_start(block[7]);                64         octeon_md5_start(block[7]);
 65 }                                                  65 }
 66                                                    66 
 67 static int octeon_md5_init(struct shash_desc *     67 static int octeon_md5_init(struct shash_desc *desc)
 68 {                                                  68 {
 69         struct md5_state *mctx = shash_desc_ct     69         struct md5_state *mctx = shash_desc_ctx(desc);
 70                                                    70 
 71         mctx->hash[0] = MD5_H0;                    71         mctx->hash[0] = MD5_H0;
 72         mctx->hash[1] = MD5_H1;                    72         mctx->hash[1] = MD5_H1;
 73         mctx->hash[2] = MD5_H2;                    73         mctx->hash[2] = MD5_H2;
 74         mctx->hash[3] = MD5_H3;                    74         mctx->hash[3] = MD5_H3;
 75         cpu_to_le32_array(mctx->hash, 4);          75         cpu_to_le32_array(mctx->hash, 4);
 76         mctx->byte_count = 0;                      76         mctx->byte_count = 0;
 77                                                    77 
 78         return 0;                                  78         return 0;
 79 }                                                  79 }
 80                                                    80 
 81 static int octeon_md5_update(struct shash_desc     81 static int octeon_md5_update(struct shash_desc *desc, const u8 *data,
 82                              unsigned int len)     82                              unsigned int len)
 83 {                                                  83 {
 84         struct md5_state *mctx = shash_desc_ct     84         struct md5_state *mctx = shash_desc_ctx(desc);
 85         const u32 avail = sizeof(mctx->block)      85         const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
 86         struct octeon_cop2_state state;            86         struct octeon_cop2_state state;
 87         unsigned long flags;                       87         unsigned long flags;
 88                                                    88 
 89         mctx->byte_count += len;                   89         mctx->byte_count += len;
 90                                                    90 
 91         if (avail > len) {                         91         if (avail > len) {
 92                 memcpy((char *)mctx->block + (     92                 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
 93                        data, len);                 93                        data, len);
 94                 return 0;                          94                 return 0;
 95         }                                          95         }
 96                                                    96 
 97         memcpy((char *)mctx->block + (sizeof(m     97         memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), data,
 98                avail);                             98                avail);
 99                                                    99 
100         flags = octeon_crypto_enable(&state);     100         flags = octeon_crypto_enable(&state);
101         octeon_md5_store_hash(mctx);              101         octeon_md5_store_hash(mctx);
102                                                   102 
103         octeon_md5_transform(mctx->block);        103         octeon_md5_transform(mctx->block);
104         data += avail;                            104         data += avail;
105         len -= avail;                             105         len -= avail;
106                                                   106 
107         while (len >= sizeof(mctx->block)) {      107         while (len >= sizeof(mctx->block)) {
108                 octeon_md5_transform(data);       108                 octeon_md5_transform(data);
109                 data += sizeof(mctx->block);      109                 data += sizeof(mctx->block);
110                 len -= sizeof(mctx->block);       110                 len -= sizeof(mctx->block);
111         }                                         111         }
112                                                   112 
113         octeon_md5_read_hash(mctx);               113         octeon_md5_read_hash(mctx);
114         octeon_crypto_disable(&state, flags);     114         octeon_crypto_disable(&state, flags);
115                                                   115 
116         memcpy(mctx->block, data, len);           116         memcpy(mctx->block, data, len);
117                                                   117 
118         return 0;                                 118         return 0;
119 }                                                 119 }
120                                                   120 
121 static int octeon_md5_final(struct shash_desc     121 static int octeon_md5_final(struct shash_desc *desc, u8 *out)
122 {                                                 122 {
123         struct md5_state *mctx = shash_desc_ct    123         struct md5_state *mctx = shash_desc_ctx(desc);
124         const unsigned int offset = mctx->byte    124         const unsigned int offset = mctx->byte_count & 0x3f;
125         char *p = (char *)mctx->block + offset    125         char *p = (char *)mctx->block + offset;
126         int padding = 56 - (offset + 1);          126         int padding = 56 - (offset + 1);
127         struct octeon_cop2_state state;           127         struct octeon_cop2_state state;
128         unsigned long flags;                      128         unsigned long flags;
129                                                   129 
130         *p++ = 0x80;                              130         *p++ = 0x80;
131                                                   131 
132         flags = octeon_crypto_enable(&state);     132         flags = octeon_crypto_enable(&state);
133         octeon_md5_store_hash(mctx);              133         octeon_md5_store_hash(mctx);
134                                                   134 
135         if (padding < 0) {                        135         if (padding < 0) {
136                 memset(p, 0x00, padding + size    136                 memset(p, 0x00, padding + sizeof(u64));
137                 octeon_md5_transform(mctx->blo    137                 octeon_md5_transform(mctx->block);
138                 p = (char *)mctx->block;          138                 p = (char *)mctx->block;
139                 padding = 56;                     139                 padding = 56;
140         }                                         140         }
141                                                   141 
142         memset(p, 0, padding);                    142         memset(p, 0, padding);
143         mctx->block[14] = mctx->byte_count <<     143         mctx->block[14] = mctx->byte_count << 3;
144         mctx->block[15] = mctx->byte_count >>     144         mctx->block[15] = mctx->byte_count >> 29;
145         cpu_to_le32_array(mctx->block + 14, 2)    145         cpu_to_le32_array(mctx->block + 14, 2);
146         octeon_md5_transform(mctx->block);        146         octeon_md5_transform(mctx->block);
147                                                   147 
148         octeon_md5_read_hash(mctx);               148         octeon_md5_read_hash(mctx);
149         octeon_crypto_disable(&state, flags);     149         octeon_crypto_disable(&state, flags);
150                                                   150 
151         memcpy(out, mctx->hash, sizeof(mctx->h    151         memcpy(out, mctx->hash, sizeof(mctx->hash));
152         memset(mctx, 0, sizeof(*mctx));           152         memset(mctx, 0, sizeof(*mctx));
153                                                   153 
154         return 0;                                 154         return 0;
155 }                                                 155 }
156                                                   156 
157 static int octeon_md5_export(struct shash_desc    157 static int octeon_md5_export(struct shash_desc *desc, void *out)
158 {                                                 158 {
159         struct md5_state *ctx = shash_desc_ctx    159         struct md5_state *ctx = shash_desc_ctx(desc);
160                                                   160 
161         memcpy(out, ctx, sizeof(*ctx));           161         memcpy(out, ctx, sizeof(*ctx));
162         return 0;                                 162         return 0;
163 }                                                 163 }
164                                                   164 
165 static int octeon_md5_import(struct shash_desc    165 static int octeon_md5_import(struct shash_desc *desc, const void *in)
166 {                                                 166 {
167         struct md5_state *ctx = shash_desc_ctx    167         struct md5_state *ctx = shash_desc_ctx(desc);
168                                                   168 
169         memcpy(ctx, in, sizeof(*ctx));            169         memcpy(ctx, in, sizeof(*ctx));
170         return 0;                                 170         return 0;
171 }                                                 171 }
172                                                   172 
173 static struct shash_alg alg = {                   173 static struct shash_alg alg = {
174         .digestsize     =       MD5_DIGEST_SIZ    174         .digestsize     =       MD5_DIGEST_SIZE,
175         .init           =       octeon_md5_ini    175         .init           =       octeon_md5_init,
176         .update         =       octeon_md5_upd    176         .update         =       octeon_md5_update,
177         .final          =       octeon_md5_fin    177         .final          =       octeon_md5_final,
178         .export         =       octeon_md5_exp    178         .export         =       octeon_md5_export,
179         .import         =       octeon_md5_imp    179         .import         =       octeon_md5_import,
180         .descsize       =       sizeof(struct     180         .descsize       =       sizeof(struct md5_state),
181         .statesize      =       sizeof(struct     181         .statesize      =       sizeof(struct md5_state),
182         .base           =       {                 182         .base           =       {
183                 .cra_name       =       "md5",    183                 .cra_name       =       "md5",
184                 .cra_driver_name=       "octeo    184                 .cra_driver_name=       "octeon-md5",
185                 .cra_priority   =       OCTEON    185                 .cra_priority   =       OCTEON_CR_OPCODE_PRIORITY,
186                 .cra_blocksize  =       MD5_HM    186                 .cra_blocksize  =       MD5_HMAC_BLOCK_SIZE,
187                 .cra_module     =       THIS_M    187                 .cra_module     =       THIS_MODULE,
188         }                                         188         }
189 };                                                189 };
190                                                   190 
191 static int __init md5_mod_init(void)              191 static int __init md5_mod_init(void)
192 {                                                 192 {
193         if (!octeon_has_crypto())                 193         if (!octeon_has_crypto())
194                 return -ENOTSUPP;                 194                 return -ENOTSUPP;
195         return crypto_register_shash(&alg);       195         return crypto_register_shash(&alg);
196 }                                                 196 }
197                                                   197 
198 static void __exit md5_mod_fini(void)             198 static void __exit md5_mod_fini(void)
199 {                                                 199 {
200         crypto_unregister_shash(&alg);            200         crypto_unregister_shash(&alg);
201 }                                                 201 }
202                                                   202 
203 module_init(md5_mod_init);                        203 module_init(md5_mod_init);
204 module_exit(md5_mod_fini);                        204 module_exit(md5_mod_fini);
205                                                   205 
206 MODULE_LICENSE("GPL");                            206 MODULE_LICENSE("GPL");
207 MODULE_DESCRIPTION("MD5 Message Digest Algorit    207 MODULE_DESCRIPTION("MD5 Message Digest Algorithm (OCTEON)");
208 MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@ik    208 MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
209                                                   209 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php