13
13
14
14
#include <crypto/algapi.h>
15
15
#include <crypto/internal/hash.h>
16
+ #include <crypto/poly1305.h>
16
17
#include <linux/crypto.h>
17
18
#include <linux/kernel.h>
18
19
#include <linux/module.h>
19
20
20
- #define POLY1305_BLOCK_SIZE 16
21
- #define POLY1305_KEY_SIZE 32
22
- #define POLY1305_DIGEST_SIZE 16
23
-
24
- struct poly1305_desc_ctx {
25
- /* key */
26
- u32 r [5 ];
27
- /* finalize key */
28
- u32 s [4 ];
29
- /* accumulator */
30
- u32 h [5 ];
31
- /* partial buffer */
32
- u8 buf [POLY1305_BLOCK_SIZE ];
33
- /* bytes used in partial buffer */
34
- unsigned int buflen ;
35
- /* r key has been set */
36
- bool rset ;
37
- /* s key has been set */
38
- bool sset ;
39
- };
40
-
41
21
static inline u64 mlt (u64 a , u64 b )
42
22
{
43
23
return a * b ;
@@ -58,7 +38,7 @@ static inline u32 le32_to_cpuvp(const void *p)
58
38
return le32_to_cpup (p );
59
39
}
60
40
61
- static int poly1305_init (struct shash_desc * desc )
41
+ int crypto_poly1305_init (struct shash_desc * desc )
62
42
{
63
43
struct poly1305_desc_ctx * dctx = shash_desc_ctx (desc );
64
44
@@ -69,8 +49,9 @@ static int poly1305_init(struct shash_desc *desc)
69
49
70
50
return 0 ;
71
51
}
52
+ EXPORT_SYMBOL_GPL (crypto_poly1305_init );
72
53
73
- static int poly1305_setkey (struct crypto_shash * tfm ,
54
+ int crypto_poly1305_setkey (struct crypto_shash * tfm ,
74
55
const u8 * key , unsigned int keylen )
75
56
{
76
57
/* Poly1305 requires a unique key for each tag, which implies that
@@ -79,6 +60,7 @@ static int poly1305_setkey(struct crypto_shash *tfm,
79
60
* the update() call. */
80
61
return - ENOTSUPP ;
81
62
}
63
+ EXPORT_SYMBOL_GPL (crypto_poly1305_setkey );
82
64
83
65
static void poly1305_setrkey (struct poly1305_desc_ctx * dctx , const u8 * key )
84
66
{
@@ -98,16 +80,10 @@ static void poly1305_setskey(struct poly1305_desc_ctx *dctx, const u8 *key)
98
80
dctx -> s [3 ] = le32_to_cpuvp (key + 12 );
99
81
}
100
82
101
- static unsigned int poly1305_blocks (struct poly1305_desc_ctx * dctx ,
102
- const u8 * src , unsigned int srclen ,
103
- u32 hibit )
83
+ unsigned int crypto_poly1305_setdesckey (struct poly1305_desc_ctx * dctx ,
84
+ const u8 * src , unsigned int srclen )
104
85
{
105
- u32 r0 , r1 , r2 , r3 , r4 ;
106
- u32 s1 , s2 , s3 , s4 ;
107
- u32 h0 , h1 , h2 , h3 , h4 ;
108
- u64 d0 , d1 , d2 , d3 , d4 ;
109
-
110
- if (unlikely (!dctx -> sset )) {
86
+ if (!dctx -> sset ) {
111
87
if (!dctx -> rset && srclen >= POLY1305_BLOCK_SIZE ) {
112
88
poly1305_setrkey (dctx , src );
113
89
src += POLY1305_BLOCK_SIZE ;
@@ -121,6 +97,25 @@ static unsigned int poly1305_blocks(struct poly1305_desc_ctx *dctx,
121
97
dctx -> sset = true;
122
98
}
123
99
}
100
+ return srclen ;
101
+ }
102
+ EXPORT_SYMBOL_GPL (crypto_poly1305_setdesckey );
103
+
104
+ static unsigned int poly1305_blocks (struct poly1305_desc_ctx * dctx ,
105
+ const u8 * src , unsigned int srclen ,
106
+ u32 hibit )
107
+ {
108
+ u32 r0 , r1 , r2 , r3 , r4 ;
109
+ u32 s1 , s2 , s3 , s4 ;
110
+ u32 h0 , h1 , h2 , h3 , h4 ;
111
+ u64 d0 , d1 , d2 , d3 , d4 ;
112
+ unsigned int datalen ;
113
+
114
+ if (unlikely (!dctx -> sset )) {
115
+ datalen = crypto_poly1305_setdesckey (dctx , src , srclen );
116
+ src += srclen - datalen ;
117
+ srclen = datalen ;
118
+ }
124
119
125
120
r0 = dctx -> r [0 ];
126
121
r1 = dctx -> r [1 ];
@@ -181,7 +176,7 @@ static unsigned int poly1305_blocks(struct poly1305_desc_ctx *dctx,
181
176
return srclen ;
182
177
}
183
178
184
- static int poly1305_update (struct shash_desc * desc ,
179
+ int crypto_poly1305_update (struct shash_desc * desc ,
185
180
const u8 * src , unsigned int srclen )
186
181
{
187
182
struct poly1305_desc_ctx * dctx = shash_desc_ctx (desc );
@@ -214,8 +209,9 @@ static int poly1305_update(struct shash_desc *desc,
214
209
215
210
return 0 ;
216
211
}
212
+ EXPORT_SYMBOL_GPL (crypto_poly1305_update );
217
213
218
- static int poly1305_final (struct shash_desc * desc , u8 * dst )
214
+ int crypto_poly1305_final (struct shash_desc * desc , u8 * dst )
219
215
{
220
216
struct poly1305_desc_ctx * dctx = shash_desc_ctx (desc );
221
217
__le32 * mac = (__le32 * )dst ;
@@ -282,13 +278,14 @@ static int poly1305_final(struct shash_desc *desc, u8 *dst)
282
278
283
279
return 0 ;
284
280
}
281
+ EXPORT_SYMBOL_GPL (crypto_poly1305_final );
285
282
286
283
static struct shash_alg poly1305_alg = {
287
284
.digestsize = POLY1305_DIGEST_SIZE ,
288
- .init = poly1305_init ,
289
- .update = poly1305_update ,
290
- .final = poly1305_final ,
291
- .setkey = poly1305_setkey ,
285
+ .init = crypto_poly1305_init ,
286
+ .update = crypto_poly1305_update ,
287
+ .final = crypto_poly1305_final ,
288
+ .setkey = crypto_poly1305_setkey ,
292
289
.descsize = sizeof (struct poly1305_desc_ctx ),
293
290
.base = {
294
291
.cra_name = "poly1305" ,
0 commit comments