Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: patches/nss-chacha20-poly1305.patch

Issue 1017413002: Uprev NSS to 3.18 RTM (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss.git@nspr_uprev
Patch Set: Rebased Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nss/lib/util/quickder.c ('k') | patches/nss-static.patch » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 diff -r c3565a90b8c4 lib/freebl/blapi.h 1 diff --git a/nss/lib/freebl/blapi.h b/nss/lib/freebl/blapi.h
2 --- a/lib/freebl/blapi.h» Fri Jan 03 20:59:10 2014 +0100 2 index 8324714..682be76 100644
3 +++ b/lib/freebl/blapi.h» Tue Jan 07 12:11:36 2014 -0800 3 --- a/nss/lib/freebl/blapi.h
4 @@ -986,6 +986,38 @@ 4 +++ b/nss/lib/freebl/blapi.h
5 @@ -986,6 +986,38 @@ Camellia_Decrypt(CamelliaContext *cx, unsigned char *output ,
5 unsigned int *outputLen, unsigned int maxOutputLen, 6 unsigned int *outputLen, unsigned int maxOutputLen,
6 const unsigned char *input, unsigned int inputLen); 7 const unsigned char *input, unsigned int inputLen);
7 8
8 +/******************************************/ 9 +/******************************************/
9 +/* 10 +/*
10 +** ChaCha20+Poly1305 AEAD 11 +** ChaCha20+Poly1305 AEAD
11 +*/ 12 +*/
12 + 13 +
13 +extern SECStatus 14 +extern SECStatus
14 +ChaCha20Poly1305_InitContext(ChaCha20Poly1305Context *ctx, 15 +ChaCha20Poly1305_InitContext(ChaCha20Poly1305Context *ctx,
(...skipping 18 matching lines...) Expand all
33 +extern SECStatus 34 +extern SECStatus
34 +ChaCha20Poly1305_Open(const ChaCha20Poly1305Context *ctx, 35 +ChaCha20Poly1305_Open(const ChaCha20Poly1305Context *ctx,
35 + unsigned char *output, unsigned int *outputLen, 36 + unsigned char *output, unsigned int *outputLen,
36 + unsigned int maxOutputLen, 37 + unsigned int maxOutputLen,
37 + const unsigned char *input, unsigned int inputLen, 38 + const unsigned char *input, unsigned int inputLen,
38 + const unsigned char *nonce, unsigned int nonceLen, 39 + const unsigned char *nonce, unsigned int nonceLen,
39 + const unsigned char *ad, unsigned int adLen); 40 + const unsigned char *ad, unsigned int adLen);
40 41
41 /******************************************/ 42 /******************************************/
42 /* 43 /*
43 diff -r c3565a90b8c4 lib/freebl/blapit.h 44 diff --git a/nss/lib/freebl/blapit.h b/nss/lib/freebl/blapit.h
44 --- a/lib/freebl/blapit.h» Fri Jan 03 20:59:10 2014 +0100 45 index 8e172d4..5726dc7 100644
45 +++ b/lib/freebl/blapit.h» Tue Jan 07 12:11:36 2014 -0800 46 --- a/nss/lib/freebl/blapit.h
46 @@ -222,6 +222,7 @@ 47 +++ b/nss/lib/freebl/blapit.h
48 @@ -222,6 +222,7 @@ struct SHA256ContextStr ;
47 struct SHA512ContextStr ; 49 struct SHA512ContextStr ;
48 struct AESKeyWrapContextStr ; 50 struct AESKeyWrapContextStr ;
49 struct SEEDContextStr ; 51 struct SEEDContextStr ;
50 +struct ChaCha20Poly1305ContextStr; 52 +struct ChaCha20Poly1305ContextStr;
51 53
52 typedef struct DESContextStr DESContext; 54 typedef struct DESContextStr DESContext;
53 typedef struct RC2ContextStr RC2Context; 55 typedef struct RC2ContextStr RC2Context;
54 @@ -240,6 +241,7 @@ 56 @@ -240,6 +241,7 @@ typedef struct SHA512ContextStr SHA512Context;
55 typedef struct SHA512ContextStr SHA384Context; 57 typedef struct SHA512ContextStr SHA384Context;
56 typedef struct AESKeyWrapContextStr AESKeyWrapContext; 58 typedef struct AESKeyWrapContextStr AESKeyWrapContext;
57 typedef struct SEEDContextStr SEEDContext; 59 typedef struct SEEDContextStr SEEDContext;
58 +typedef struct ChaCha20Poly1305ContextStr ChaCha20Poly1305Context; 60 +typedef struct ChaCha20Poly1305ContextStr ChaCha20Poly1305Context;
59 61
60 /*************************************************************************** 62 /***************************************************************************
61 ** RSA Public and Private Key structures 63 ** RSA Public and Private Key structures
62 diff -r c3565a90b8c4 lib/freebl/chacha20/chacha20.c 64 diff --git a/nss/lib/freebl/chacha20/chacha20.c b/nss/lib/freebl/chacha20/chacha 20.c
63 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 65 new file mode 100644
64 +++ b/lib/freebl/chacha20/chacha20.c» Tue Jan 07 12:11:36 2014 -0800 66 index 0000000..ca0b1ff
67 --- /dev/null
68 +++ b/nss/lib/freebl/chacha20/chacha20.c
65 @@ -0,0 +1,108 @@ 69 @@ -0,0 +1,108 @@
66 +/* This Source Code Form is subject to the terms of the Mozilla Public 70 +/* This Source Code Form is subject to the terms of the Mozilla Public
67 + * License, v. 2.0. If a copy of the MPL was not distributed with this 71 + * License, v. 2.0. If a copy of the MPL was not distributed with this
68 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 72 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
69 + 73 +
70 +/* Adopted from the public domain code in NaCl by djb. */ 74 +/* Adopted from the public domain code in NaCl by djb. */
71 + 75 +
72 +#include <string.h> 76 +#include <string.h>
73 +#include <stdio.h> 77 +#include <stdio.h>
74 + 78 +
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 + out += 64; 168 + out += 64;
165 + } 169 + }
166 + 170 +
167 + if (inLen > 0) { 171 + if (inLen > 0) {
168 + ChaChaCore(block, input, 20); 172 + ChaChaCore(block, input, 20);
169 + for (i = 0; i < inLen; i++) { 173 + for (i = 0; i < inLen; i++) {
170 + out[i] = in[i] ^ block[i]; 174 + out[i] = in[i] ^ block[i];
171 + } 175 + }
172 + } 176 + }
173 +} 177 +}
174 diff -r c3565a90b8c4 lib/freebl/chacha20/chacha20.h 178 diff --git a/nss/lib/freebl/chacha20/chacha20.h b/nss/lib/freebl/chacha20/chacha 20.h
175 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 179 new file mode 100644
176 +++ b/lib/freebl/chacha20/chacha20.h» Tue Jan 07 12:11:36 2014 -0800 180 index 0000000..6336ba7
181 --- /dev/null
182 +++ b/nss/lib/freebl/chacha20/chacha20.h
177 @@ -0,0 +1,22 @@ 183 @@ -0,0 +1,22 @@
178 +/* 184 +/*
179 + * chacha20.h - header file for ChaCha20 implementation. 185 + * chacha20.h - header file for ChaCha20 implementation.
180 + * 186 + *
181 + * This Source Code Form is subject to the terms of the Mozilla Public 187 + * This Source Code Form is subject to the terms of the Mozilla Public
182 + * License, v. 2.0. If a copy of the MPL was not distributed with this 188 + * License, v. 2.0. If a copy of the MPL was not distributed with this
183 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 189 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
184 + 190 +
185 +#ifndef FREEBL_CHACHA20_H_ 191 +#ifndef FREEBL_CHACHA20_H_
186 +#define FREEBL_CHACHA20_H_ 192 +#define FREEBL_CHACHA20_H_
187 + 193 +
188 +#include <stdint.h> 194 +#include <stdint.h>
189 + 195 +
190 +/* ChaCha20XOR encrypts |inLen| bytes from |in| with the given key and 196 +/* ChaCha20XOR encrypts |inLen| bytes from |in| with the given key and
191 + * nonce and writes the result to |out|, which may be equal to |in|. The 197 + * nonce and writes the result to |out|, which may be equal to |in|. The
192 + * initial block counter is specified by |counter|. */ 198 + * initial block counter is specified by |counter|. */
193 +extern void ChaCha20XOR(unsigned char *out, 199 +extern void ChaCha20XOR(unsigned char *out,
194 + const unsigned char *in, unsigned int inLen, 200 + const unsigned char *in, unsigned int inLen,
195 + const unsigned char key[32], 201 + const unsigned char key[32],
196 + const unsigned char nonce[8], 202 + const unsigned char nonce[8],
197 + uint64_t counter); 203 + uint64_t counter);
198 + 204 +
199 +#endif /* FREEBL_CHACHA20_H_ */ 205 +#endif /* FREEBL_CHACHA20_H_ */
200 diff -r c3565a90b8c4 lib/freebl/chacha20/chacha20_vec.c 206 diff --git a/nss/lib/freebl/chacha20/chacha20_vec.c b/nss/lib/freebl/chacha20/ch acha20_vec.c
201 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 207 new file mode 100644
202 +++ b/lib/freebl/chacha20/chacha20_vec.c» Tue Jan 07 12:11:36 2014 -0800 208 index 0000000..c3573b3
209 --- /dev/null
210 +++ b/nss/lib/freebl/chacha20/chacha20_vec.c
203 @@ -0,0 +1,281 @@ 211 @@ -0,0 +1,281 @@
204 +/* This Source Code Form is subject to the terms of the Mozilla Public 212 +/* This Source Code Form is subject to the terms of the Mozilla Public
205 + * License, v. 2.0. If a copy of the MPL was not distributed with this 213 + * License, v. 2.0. If a copy of the MPL was not distributed with this
206 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 214 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
207 + 215 +
208 +/* This implementation is by Ted Krovetz and was submitted to SUPERCOP and 216 +/* This implementation is by Ted Krovetz and was submitted to SUPERCOP and
209 + * marked as public domain. It was been altered to allow for non-aligned inputs 217 + * marked as public domain. It was been altered to allow for non-aligned inputs
210 + * and to allow the block counter to be passed in specifically. */ 218 + * and to allow the block counter to be passed in specifically. */
211 + 219 +
212 +#include <string.h> 220 +#include <string.h>
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 + } 483 + }
476 + } else { 484 + } else {
477 + buf[0] = REVV_BE(v0 + s0); 485 + buf[0] = REVV_BE(v0 + s0);
478 + } 486 + }
479 + 487 +
480 + for (i=inlen & ~15; i<inlen; i++) { 488 + for (i=inlen & ~15; i<inlen; i++) {
481 + ((char *)op)[i] = ((char *)ip)[i] ^ ((char *)buf)[i]; 489 + ((char *)op)[i] = ((char *)ip)[i] ^ ((char *)buf)[i];
482 + } 490 + }
483 + } 491 + }
484 +} 492 +}
485 diff -r c3565a90b8c4 lib/freebl/chacha20poly1305.c 493 diff --git a/nss/lib/freebl/chacha20poly1305.c b/nss/lib/freebl/chacha20poly1305 .c
486 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 494 new file mode 100644
487 +++ b/lib/freebl/chacha20poly1305.c» Tue Jan 07 12:11:36 2014 -0800 495 index 0000000..6fa5c4b
496 --- /dev/null
497 +++ b/nss/lib/freebl/chacha20poly1305.c
488 @@ -0,0 +1,169 @@ 498 @@ -0,0 +1,169 @@
489 +/* This Source Code Form is subject to the terms of the Mozilla Public 499 +/* This Source Code Form is subject to the terms of the Mozilla Public
490 + * License, v. 2.0. If a copy of the MPL was not distributed with this 500 + * License, v. 2.0. If a copy of the MPL was not distributed with this
491 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 501 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
492 + 502 +
493 +#ifdef FREEBL_NO_DEPEND 503 +#ifdef FREEBL_NO_DEPEND
494 +#include "stubs.h" 504 +#include "stubs.h"
495 +#endif 505 +#endif
496 + 506 +
497 +#include <string.h> 507 +#include <string.h>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 + Poly1305Do(tag, ad, adLen, input, inputLen - ctx->tagLen, block); 658 + Poly1305Do(tag, ad, adLen, input, inputLen - ctx->tagLen, block);
649 + if (NSS_SecureMemcmp(tag, &input[inputLen - ctx->tagLen], ctx->tagLen) != 0 ) { 659 + if (NSS_SecureMemcmp(tag, &input[inputLen - ctx->tagLen], ctx->tagLen) != 0 ) {
650 + PORT_SetError(SEC_ERROR_BAD_DATA); 660 + PORT_SetError(SEC_ERROR_BAD_DATA);
651 + return SECFailure; 661 + return SECFailure;
652 + } 662 + }
653 + 663 +
654 + ChaCha20XOR(output, input, inputLen - ctx->tagLen, ctx->key, nonce, 1); 664 + ChaCha20XOR(output, input, inputLen - ctx->tagLen, ctx->key, nonce, 1);
655 + 665 +
656 + return SECSuccess; 666 + return SECSuccess;
657 +} 667 +}
658 diff -r c3565a90b8c4 lib/freebl/chacha20poly1305.h 668 diff --git a/nss/lib/freebl/chacha20poly1305.h b/nss/lib/freebl/chacha20poly1305 .h
659 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 669 new file mode 100644
660 +++ b/lib/freebl/chacha20poly1305.h» Tue Jan 07 12:11:36 2014 -0800 670 index 0000000..c77632a
671 --- /dev/null
672 +++ b/nss/lib/freebl/chacha20poly1305.h
661 @@ -0,0 +1,15 @@ 673 @@ -0,0 +1,15 @@
662 +/* This Source Code Form is subject to the terms of the Mozilla Public 674 +/* This Source Code Form is subject to the terms of the Mozilla Public
663 + * License, v. 2.0. If a copy of the MPL was not distributed with this 675 + * License, v. 2.0. If a copy of the MPL was not distributed with this
664 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 676 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
665 + 677 +
666 +#ifndef _CHACHA20_POLY1305_H_ 678 +#ifndef _CHACHA20_POLY1305_H_
667 +#define _CHACHA20_POLY1305_H_ 1 679 +#define _CHACHA20_POLY1305_H_ 1
668 + 680 +
669 +/* ChaCha20Poly1305ContextStr saves the key and tag length for a 681 +/* ChaCha20Poly1305ContextStr saves the key and tag length for a
670 + * ChaCha20+Poly1305 AEAD operation. */ 682 + * ChaCha20+Poly1305 AEAD operation. */
671 +struct ChaCha20Poly1305ContextStr { 683 +struct ChaCha20Poly1305ContextStr {
672 + unsigned char key[32]; 684 + unsigned char key[32];
673 + unsigned char tagLen; 685 + unsigned char tagLen;
674 +}; 686 +};
675 + 687 +
676 +#endif /* _CHACHA20_POLY1305_H_ */ 688 +#endif /* _CHACHA20_POLY1305_H_ */
677 diff -r c3565a90b8c4 lib/freebl/poly1305/poly1305-donna-x64-sse2-incremental-sou rce.c 689 diff --git a/nss/lib/freebl/poly1305/poly1305-donna-x64-sse2-incremental-source. c b/nss/lib/freebl/poly1305/poly1305-donna-x64-sse2-incremental-source.c
678 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 690 new file mode 100644
679 +++ b/lib/freebl/poly1305/poly1305-donna-x64-sse2-incremental-source.c» Tue Jan 07 12:11:36 2014 -0800 691 index 0000000..38cbf35
692 --- /dev/null
693 +++ b/nss/lib/freebl/poly1305/poly1305-donna-x64-sse2-incremental-source.c
680 @@ -0,0 +1,623 @@ 694 @@ -0,0 +1,623 @@
681 +/* This Source Code Form is subject to the terms of the Mozilla Public 695 +/* This Source Code Form is subject to the terms of the Mozilla Public
682 + * License, v. 2.0. If a copy of the MPL was not distributed with this 696 + * License, v. 2.0. If a copy of the MPL was not distributed with this
683 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 697 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
684 + 698 +
685 +/* This implementation of poly1305 is by Andrew Moon 699 +/* This implementation of poly1305 is by Andrew Moon
686 + * (https://github.com/floodyberry/poly1305-donna) and released as public 700 + * (https://github.com/floodyberry/poly1305-donna) and released as public
687 + * domain. It implements SIMD vectorization based on the algorithm described in 701 + * domain. It implements SIMD vectorization based on the algorithm described in
688 + * http://cr.yp.to/papers.html#neoncrypto. Unrolled to 2 powers, i.e. 64 byte 702 + * http://cr.yp.to/papers.html#neoncrypto. Unrolled to 2 powers, i.e. 64 byte
689 + * block size. */ 703 + * block size. */
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 + /* pad */ 1308 + /* pad */
1295 + t0 = ((uint64_t)p->R23.d[3] << 32) | (uint64_t)p->R23.d[1]; 1309 + t0 = ((uint64_t)p->R23.d[3] << 32) | (uint64_t)p->R23.d[1];
1296 + t1 = ((uint64_t)p->R24.d[3] << 32) | (uint64_t)p->R24.d[1]; 1310 + t1 = ((uint64_t)p->R24.d[3] << 32) | (uint64_t)p->R24.d[1];
1297 + h0 += (t0 & 0xfffffffffff) ; c = (h0 >> 44); h0 &= 0xfffffffffff; t0 = shr128_pair(t1, t0, 44); 1311 + h0 += (t0 & 0xfffffffffff) ; c = (h0 >> 44); h0 &= 0xfffffffffff; t0 = shr128_pair(t1, t0, 44);
1298 + h1 += (t0 & 0xfffffffffff) + c; c = (h1 >> 44); h1 &= 0xfffffffffff; t1 = (t1 >> 24); 1312 + h1 += (t0 & 0xfffffffffff) + c; c = (h1 >> 44); h1 &= 0xfffffffffff; t1 = (t1 >> 24);
1299 + h2 += (t1 ) + c; 1313 + h2 += (t1 ) + c;
1300 + 1314 +
1301 + U64TO8_LE(mac + 0, ((h0 ) | (h1 << 44))); 1315 + U64TO8_LE(mac + 0, ((h0 ) | (h1 << 44)));
1302 + U64TO8_LE(mac + 8, ((h1 >> 20) | (h2 << 24))); 1316 + U64TO8_LE(mac + 8, ((h1 >> 20) | (h2 << 24)));
1303 +} 1317 +}
1304 diff -r c3565a90b8c4 lib/freebl/poly1305/poly1305.c 1318 diff --git a/nss/lib/freebl/poly1305/poly1305.c b/nss/lib/freebl/poly1305/poly13 05.c
1305 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 1319 new file mode 100644
1306 +++ b/lib/freebl/poly1305/poly1305.c» Tue Jan 07 12:11:36 2014 -0800 1320 index 0000000..d86048a
1321 --- /dev/null
1322 +++ b/nss/lib/freebl/poly1305/poly1305.c
1307 @@ -0,0 +1,254 @@ 1323 @@ -0,0 +1,254 @@
1308 +/* This Source Code Form is subject to the terms of the Mozilla Public 1324 +/* This Source Code Form is subject to the terms of the Mozilla Public
1309 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1325 + * License, v. 2.0. If a copy of the MPL was not distributed with this
1310 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1326 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1311 + 1327 +
1312 +/* This implementation of poly1305 is by Andrew Moon 1328 +/* This implementation of poly1305 is by Andrew Moon
1313 + * (https://github.com/floodyberry/poly1305-donna) and released as public 1329 + * (https://github.com/floodyberry/poly1305-donna) and released as public
1314 + * domain. */ 1330 + * domain. */
1315 + 1331 +
1316 +#include <string.h> 1332 +#include <string.h>
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 + f0 = ((state->h0 ) | (state->h1 << 26)) + (uint64_t)U8TO32_LE(&stat e->key[0]); 1568 + f0 = ((state->h0 ) | (state->h1 << 26)) + (uint64_t)U8TO32_LE(&stat e->key[0]);
1553 + f1 = ((state->h1 >> 6) | (state->h2 << 20)) + (uint64_t)U8TO32_LE(&stat e->key[4]); 1569 + f1 = ((state->h1 >> 6) | (state->h2 << 20)) + (uint64_t)U8TO32_LE(&stat e->key[4]);
1554 + f2 = ((state->h2 >> 12) | (state->h3 << 14)) + (uint64_t)U8TO32_LE(&stat e->key[8]); 1570 + f2 = ((state->h2 >> 12) | (state->h3 << 14)) + (uint64_t)U8TO32_LE(&stat e->key[8]);
1555 + f3 = ((state->h3 >> 18) | (state->h4 << 8)) + (uint64_t)U8TO32_LE(&stat e->key[12]); 1571 + f3 = ((state->h3 >> 18) | (state->h4 << 8)) + (uint64_t)U8TO32_LE(&stat e->key[12]);
1556 + 1572 +
1557 + U32TO8_LE(&mac[ 0], (uint32_t)f0); f1 += (f0 >> 32); 1573 + U32TO8_LE(&mac[ 0], (uint32_t)f0); f1 += (f0 >> 32);
1558 + U32TO8_LE(&mac[ 4], (uint32_t)f1); f2 += (f1 >> 32); 1574 + U32TO8_LE(&mac[ 4], (uint32_t)f1); f2 += (f1 >> 32);
1559 + U32TO8_LE(&mac[ 8], (uint32_t)f2); f3 += (f2 >> 32); 1575 + U32TO8_LE(&mac[ 8], (uint32_t)f2); f3 += (f2 >> 32);
1560 + U32TO8_LE(&mac[12], (uint32_t)f3); 1576 + U32TO8_LE(&mac[12], (uint32_t)f3);
1561 +} 1577 +}
1562 diff -r c3565a90b8c4 lib/freebl/poly1305/poly1305.h 1578 diff --git a/nss/lib/freebl/poly1305/poly1305.h b/nss/lib/freebl/poly1305/poly13 05.h
1563 --- /dev/null» Thu Jan 01 00:00:00 1970 +0000 1579 new file mode 100644
1564 +++ b/lib/freebl/poly1305/poly1305.h» Tue Jan 07 12:11:36 2014 -0800 1580 index 0000000..4beb172
1581 --- /dev/null
1582 +++ b/nss/lib/freebl/poly1305/poly1305.h
1565 @@ -0,0 +1,31 @@ 1583 @@ -0,0 +1,31 @@
1566 +/* 1584 +/*
1567 + * poly1305.h - header file for Poly1305 implementation. 1585 + * poly1305.h - header file for Poly1305 implementation.
1568 + * 1586 + *
1569 + * This Source Code Form is subject to the terms of the Mozilla Public 1587 + * This Source Code Form is subject to the terms of the Mozilla Public
1570 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1588 + * License, v. 2.0. If a copy of the MPL was not distributed with this
1571 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1589 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1572 + 1590 +
1573 +#ifndef FREEBL_POLY1305_H_ 1591 +#ifndef FREEBL_POLY1305_H_
1574 +#define FREEBL_POLY1305_H_ 1592 +#define FREEBL_POLY1305_H_
(...skipping 12 matching lines...) Expand all
1587 +extern void Poly1305Update(poly1305_state* state, 1605 +extern void Poly1305Update(poly1305_state* state,
1588 + const unsigned char *in, 1606 + const unsigned char *in,
1589 + size_t inLen); 1607 + size_t inLen);
1590 + 1608 +
1591 +/* Poly1305Finish completes the poly1305 calculation and writes a 16 byte 1609 +/* Poly1305Finish completes the poly1305 calculation and writes a 16 byte
1592 + * authentication tag to |mac|. */ 1610 + * authentication tag to |mac|. */
1593 +extern void Poly1305Finish(poly1305_state* state, 1611 +extern void Poly1305Finish(poly1305_state* state,
1594 + unsigned char mac[16]); 1612 + unsigned char mac[16]);
1595 + 1613 +
1596 +#endif /* FREEBL_POLY1305_H_ */ 1614 +#endif /* FREEBL_POLY1305_H_ */
1597 diff -r c3565a90b8c4 lib/pk11wrap/pk11mech.c 1615 diff --git a/nss/lib/pk11wrap/pk11mech.c b/nss/lib/pk11wrap/pk11mech.c
1598 --- a/lib/pk11wrap/pk11mech.c» Fri Jan 03 20:59:10 2014 +0100 1616 index b7a7296..edc7a9b 100644
1599 +++ b/lib/pk11wrap/pk11mech.c» Tue Jan 07 12:11:36 2014 -0800 1617 --- a/nss/lib/pk11wrap/pk11mech.c
1600 @@ -152,6 +152,8 @@ 1618 +++ b/nss/lib/pk11wrap/pk11mech.c
1619 @@ -152,6 +152,8 @@ PK11_GetKeyMechanism(CK_KEY_TYPE type)
1601 return CKM_SEED_CBC; 1620 return CKM_SEED_CBC;
1602 case CKK_CAMELLIA: 1621 case CKK_CAMELLIA:
1603 return CKM_CAMELLIA_CBC; 1622 return CKM_CAMELLIA_CBC;
1604 + case CKK_NSS_CHACHA20: 1623 + case CKK_NSS_CHACHA20:
1605 + return CKM_NSS_CHACHA20_POLY1305; 1624 + return CKM_NSS_CHACHA20_POLY1305;
1606 case CKK_AES: 1625 case CKK_AES:
1607 return CKM_AES_CBC; 1626 return CKM_AES_CBC;
1608 case CKK_DES: 1627 case CKK_DES:
1609 @@ -219,6 +221,8 @@ 1628 @@ -219,6 +221,8 @@ PK11_GetKeyType(CK_MECHANISM_TYPE type,unsigned long len)
1610 case CKM_CAMELLIA_CBC_PAD: 1629 case CKM_CAMELLIA_CBC_PAD:
1611 case CKM_CAMELLIA_KEY_GEN: 1630 case CKM_CAMELLIA_KEY_GEN:
1612 return CKK_CAMELLIA; 1631 return CKK_CAMELLIA;
1613 + case CKM_NSS_CHACHA20_POLY1305: 1632 + case CKM_NSS_CHACHA20_POLY1305:
1614 + return CKK_NSS_CHACHA20; 1633 + return CKK_NSS_CHACHA20;
1615 case CKM_AES_ECB: 1634 case CKM_AES_ECB:
1616 case CKM_AES_CBC: 1635 case CKM_AES_CBC:
1617 case CKM_AES_CCM: 1636 case CKM_AES_CCM:
1618 @@ -429,6 +433,8 @@ 1637 @@ -429,6 +433,8 @@ PK11_GetKeyGenWithSize(CK_MECHANISM_TYPE type, int size)
1619 case CKM_CAMELLIA_CBC_PAD: 1638 case CKM_CAMELLIA_CBC_PAD:
1620 case CKM_CAMELLIA_KEY_GEN: 1639 case CKM_CAMELLIA_KEY_GEN:
1621 return CKM_CAMELLIA_KEY_GEN; 1640 return CKM_CAMELLIA_KEY_GEN;
1622 + case CKM_NSS_CHACHA20_POLY1305: 1641 + case CKM_NSS_CHACHA20_POLY1305:
1623 + return CKM_NSS_CHACHA20_KEY_GEN; 1642 + return CKM_NSS_CHACHA20_KEY_GEN;
1624 case CKM_AES_ECB: 1643 case CKM_AES_ECB:
1625 case CKM_AES_CBC: 1644 case CKM_AES_CBC:
1626 case CKM_AES_CCM: 1645 case CKM_AES_CCM:
1627 diff -r c3565a90b8c4 lib/softoken/pkcs11.c 1646 diff --git a/nss/lib/softoken/pkcs11.c b/nss/lib/softoken/pkcs11.c
1628 --- a/lib/softoken/pkcs11.c» Fri Jan 03 20:59:10 2014 +0100 1647 index bd7c4bd..716922f 100644
1629 +++ b/lib/softoken/pkcs11.c» Tue Jan 07 12:11:36 2014 -0800 1648 --- a/nss/lib/softoken/pkcs11.c
1630 @@ -368,6 +368,9 @@ 1649 +++ b/nss/lib/softoken/pkcs11.c
1650 @@ -370,6 +370,9 @@ static const struct mechanismList mechanisms[] = {
1631 {CKM_SEED_MAC, {16, 16, CKF_SN_VR}, PR_TRUE}, 1651 {CKM_SEED_MAC, {16, 16, CKF_SN_VR}, PR_TRUE},
1632 {CKM_SEED_MAC_GENERAL, {16, 16, CKF_SN_VR}, PR_TRUE}, 1652 {CKM_SEED_MAC_GENERAL, {16, 16, CKF_SN_VR}, PR_TRUE},
1633 {CKM_SEED_CBC_PAD, {16, 16, CKF_EN_DE_WR_UN}, PR_TRUE} , 1653 {CKM_SEED_CBC_PAD, {16, 16, CKF_EN_DE_WR_UN}, PR_TRUE} ,
1634 + /* ------------------------- ChaCha20 Operations ---------------------- */ 1654 + /* ------------------------- ChaCha20 Operations ---------------------- */
1635 + {CKM_NSS_CHACHA20_KEY_GEN, {32, 32, CKF_GENERATE}, PR_TRUE} , 1655 + {CKM_NSS_CHACHA20_KEY_GEN, {32, 32, CKF_GENERATE}, PR_TRUE} ,
1636 + {CKM_NSS_CHACHA20_POLY1305,{32, 32, CKF_EN_DE}, PR_TRUE}, 1656 + {CKM_NSS_CHACHA20_POLY1305,{32, 32, CKF_EN_DE}, PR_TRUE},
1637 /* ------------------------- Hashing Operations ----------------------- */ 1657 /* ------------------------- Hashing Operations ----------------------- */
1638 {CKM_MD2, {0, 0, CKF_DIGEST}, PR_FALSE}, 1658 {CKM_MD2, {0, 0, CKF_DIGEST}, PR_FALSE},
1639 {CKM_MD2_HMAC, {1, 128, CKF_SN_VR}, PR_TRUE}, 1659 {CKM_MD2_HMAC, {1, 128, CKF_SN_VR}, PR_TRUE},
1640 diff -r c3565a90b8c4 lib/softoken/pkcs11c.c 1660 diff --git a/nss/lib/softoken/pkcs11c.c b/nss/lib/softoken/pkcs11c.c
1641 --- a/lib/softoken/pkcs11c.c» Fri Jan 03 20:59:10 2014 +0100 1661 index fc050f3..955d4c9 100644
1642 +++ b/lib/softoken/pkcs11c.c» Tue Jan 07 12:11:36 2014 -0800 1662 --- a/nss/lib/softoken/pkcs11c.c
1643 @@ -632,6 +632,97 @@ 1663 +++ b/nss/lib/softoken/pkcs11c.c
1664 @@ -663,6 +663,97 @@ sftk_RSADecryptOAEP(SFTKOAEPDecryptInfo *info, unsigned cha r *output,
1644 return rv; 1665 return rv;
1645 } 1666 }
1646 1667
1647 +static SFTKChaCha20Poly1305Info * 1668 +static SFTKChaCha20Poly1305Info *
1648 +sftk_ChaCha20Poly1305_CreateContext(const unsigned char *key, 1669 +sftk_ChaCha20Poly1305_CreateContext(const unsigned char *key,
1649 + unsigned int keyLen, 1670 + unsigned int keyLen,
1650 + const CK_NSS_AEAD_PARAMS* params) 1671 + const CK_NSS_AEAD_PARAMS* params)
1651 +{ 1672 +{
1652 + SFTKChaCha20Poly1305Info *ctx; 1673 + SFTKChaCha20Poly1305Info *ctx;
1653 + 1674 +
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 + } 1752 + }
1732 + 1753 +
1733 + return ChaCha20Poly1305_Open(&ctx->freeblCtx, output, outputLen, 1754 + return ChaCha20Poly1305_Open(&ctx->freeblCtx, output, outputLen,
1734 + maxOutputLen, input, inputLen, ctx->nonce, 1755 + maxOutputLen, input, inputLen, ctx->nonce,
1735 + sizeof(ctx->nonce), ad, ctx->adLen); 1756 + sizeof(ctx->nonce), ad, ctx->adLen);
1736 +} 1757 +}
1737 + 1758 +
1738 /** NSC_CryptInit initializes an encryption/Decryption operation. 1759 /** NSC_CryptInit initializes an encryption/Decryption operation.
1739 * 1760 *
1740 * Always called by NSC_EncryptInit, NSC_DecryptInit, NSC_WrapKey,NSC_UnwrapKey . 1761 * Always called by NSC_EncryptInit, NSC_DecryptInit, NSC_WrapKey,NSC_UnwrapKey .
1741 @@ -1027,6 +1118,35 @@ 1762 @@ -1056,6 +1147,35 @@ finish_des:
1742 context->destroy = (SFTKDestroy) AES_DestroyContext; 1763 context->destroy = (SFTKDestroy) AES_DestroyContext;
1743 break; 1764 break;
1744 1765
1745 + case CKM_NSS_CHACHA20_POLY1305: 1766 + case CKM_NSS_CHACHA20_POLY1305:
1746 + if (pMechanism->ulParameterLen != sizeof(CK_NSS_AEAD_PARAMS)) { 1767 + if (pMechanism->ulParameterLen != sizeof(CK_NSS_AEAD_PARAMS)) {
1747 + crv = CKR_MECHANISM_PARAM_INVALID; 1768 + crv = CKR_MECHANISM_PARAM_INVALID;
1748 + break; 1769 + break;
1749 + } 1770 + }
1750 + context->multi = PR_FALSE; 1771 + context->multi = PR_FALSE;
1751 + if (key_type != CKK_NSS_CHACHA20) { 1772 + if (key_type != CKK_NSS_CHACHA20) {
(...skipping 15 matching lines...) Expand all
1767 + } 1788 + }
1768 + context->update = (SFTKCipher) (isEncrypt ? 1789 + context->update = (SFTKCipher) (isEncrypt ?
1769 + sftk_ChaCha20Poly1305_Encrypt : 1790 + sftk_ChaCha20Poly1305_Encrypt :
1770 + sftk_ChaCha20Poly1305_Decrypt); 1791 + sftk_ChaCha20Poly1305_Decrypt);
1771 + context->destroy = (SFTKDestroy) sftk_ChaCha20Poly1305_DestroyContext; 1792 + context->destroy = (SFTKDestroy) sftk_ChaCha20Poly1305_DestroyContext;
1772 + break; 1793 + break;
1773 + 1794 +
1774 case CKM_NETSCAPE_AES_KEY_WRAP_PAD: 1795 case CKM_NETSCAPE_AES_KEY_WRAP_PAD:
1775 context->doPad = PR_TRUE; 1796 context->doPad = PR_TRUE;
1776 /* fall thru */ 1797 /* fall thru */
1777 @@ -3601,6 +3721,10 @@ 1798 @@ -3609,6 +3729,10 @@ nsc_SetupBulkKeyGen(CK_MECHANISM_TYPE mechanism, CK_KEY_T YPE *key_type,
1778 *key_type = CKK_AES; 1799 *key_type = CKK_AES;
1779 if (*key_length == 0) crv = CKR_TEMPLATE_INCOMPLETE; 1800 if (*key_length == 0) crv = CKR_TEMPLATE_INCOMPLETE;
1780 break; 1801 break;
1781 + case CKM_NSS_CHACHA20_KEY_GEN: 1802 + case CKM_NSS_CHACHA20_KEY_GEN:
1782 + *key_type = CKK_NSS_CHACHA20; 1803 + *key_type = CKK_NSS_CHACHA20;
1783 + if (*key_length == 0) crv = CKR_TEMPLATE_INCOMPLETE; 1804 + if (*key_length == 0) crv = CKR_TEMPLATE_INCOMPLETE;
1784 + break; 1805 + break;
1785 default: 1806 default:
1786 PORT_Assert(0); 1807 PORT_Assert(0);
1787 crv = CKR_MECHANISM_INVALID; 1808 crv = CKR_MECHANISM_INVALID;
1788 @@ -3846,6 +3970,7 @@ 1809 @@ -3854,6 +3978,7 @@ CK_RV NSC_GenerateKey(CK_SESSION_HANDLE hSession,
1789 case CKM_SEED_KEY_GEN: 1810 case CKM_SEED_KEY_GEN:
1790 case CKM_CAMELLIA_KEY_GEN: 1811 case CKM_CAMELLIA_KEY_GEN:
1791 case CKM_AES_KEY_GEN: 1812 case CKM_AES_KEY_GEN:
1792 + case CKM_NSS_CHACHA20_KEY_GEN: 1813 + case CKM_NSS_CHACHA20_KEY_GEN:
1793 #if NSS_SOFTOKEN_DOES_RC5 1814 #if NSS_SOFTOKEN_DOES_RC5
1794 case CKM_RC5_KEY_GEN: 1815 case CKM_RC5_KEY_GEN:
1795 #endif 1816 #endif
1796 diff -r c3565a90b8c4 lib/softoken/pkcs11i.h 1817 diff --git a/nss/lib/softoken/pkcs11i.h b/nss/lib/softoken/pkcs11i.h
1797 --- a/lib/softoken/pkcs11i.h» Fri Jan 03 20:59:10 2014 +0100 1818 index 9a00273..175bb78 100644
1798 +++ b/lib/softoken/pkcs11i.h» Tue Jan 07 12:11:36 2014 -0800 1819 --- a/nss/lib/softoken/pkcs11i.h
1820 +++ b/nss/lib/softoken/pkcs11i.h
1799 @@ -14,6 +14,7 @@ 1821 @@ -14,6 +14,7 @@
1800 #include "pkcs11t.h" 1822 #include "pkcs11t.h"
1801 1823
1802 #include "sftkdbt.h" 1824 #include "sftkdbt.h"
1803 +#include "chacha20poly1305.h" 1825 +#include "chacha20poly1305.h"
1804 #include "hasht.h" 1826 #include "hasht.h"
1805 1827
1806 /* 1828 /*
1807 @@ -104,6 +105,7 @@ 1829 @@ -104,6 +105,7 @@ typedef struct SFTKHashSignInfoStr SFTKHashSignInfo;
1808 typedef struct SFTKOAEPEncryptInfoStr SFTKOAEPEncryptInfo; 1830 typedef struct SFTKOAEPEncryptInfoStr SFTKOAEPEncryptInfo;
1809 typedef struct SFTKOAEPDecryptInfoStr SFTKOAEPDecryptInfo; 1831 typedef struct SFTKOAEPDecryptInfoStr SFTKOAEPDecryptInfo;
1810 typedef struct SFTKSSLMACInfoStr SFTKSSLMACInfo; 1832 typedef struct SFTKSSLMACInfoStr SFTKSSLMACInfo;
1811 +typedef struct SFTKChaCha20Poly1305InfoStr SFTKChaCha20Poly1305Info; 1833 +typedef struct SFTKChaCha20Poly1305InfoStr SFTKChaCha20Poly1305Info;
1812 typedef struct SFTKItemTemplateStr SFTKItemTemplate; 1834 typedef struct SFTKItemTemplateStr SFTKItemTemplate;
1813 1835
1814 /* define function pointer typdefs for pointer tables */ 1836 /* define function pointer typdefs for pointer tables */
1815 @@ -399,6 +401,16 @@ 1837 @@ -399,6 +401,16 @@ struct SFTKSSLMACInfoStr {
1816 unsigned int keySize; 1838 unsigned int keySize;
1817 }; 1839 };
1818 1840
1819 +/* SFTKChaCha20Poly1305Info saves the key, tag length, nonce, and additional 1841 +/* SFTKChaCha20Poly1305Info saves the key, tag length, nonce, and additional
1820 + * data for a ChaCha20+Poly1305 AEAD operation. */ 1842 + * data for a ChaCha20+Poly1305 AEAD operation. */
1821 +struct SFTKChaCha20Poly1305InfoStr { 1843 +struct SFTKChaCha20Poly1305InfoStr {
1822 + ChaCha20Poly1305Context freeblCtx; 1844 + ChaCha20Poly1305Context freeblCtx;
1823 + unsigned char nonce[8]; 1845 + unsigned char nonce[8];
1824 + unsigned char ad[16]; 1846 + unsigned char ad[16];
1825 + unsigned char *adOverflow; 1847 + unsigned char *adOverflow;
1826 + unsigned int adLen; 1848 + unsigned int adLen;
1827 +}; 1849 +};
1828 + 1850 +
1829 /* 1851 /*
1830 * Template based on SECItems, suitable for passing as arrays 1852 * Template based on SECItems, suitable for passing as arrays
1831 */ 1853 */
1832 diff -r c3565a90b8c4 lib/util/pkcs11n.h 1854 diff --git a/nss/lib/util/pkcs11n.h b/nss/lib/util/pkcs11n.h
1833 --- a/lib/util/pkcs11n.h» Fri Jan 03 20:59:10 2014 +0100 1855 index a1a0ebb..d48cef6 100644
1834 +++ b/lib/util/pkcs11n.h» Tue Jan 07 12:11:36 2014 -0800 1856 --- a/nss/lib/util/pkcs11n.h
1857 +++ b/nss/lib/util/pkcs11n.h
1835 @@ -51,6 +51,8 @@ 1858 @@ -51,6 +51,8 @@
1836 #define CKK_NSS_JPAKE_ROUND1 (CKK_NSS + 2) 1859 #define CKK_NSS_JPAKE_ROUND1 (CKK_NSS + 2)
1837 #define CKK_NSS_JPAKE_ROUND2 (CKK_NSS + 3) 1860 #define CKK_NSS_JPAKE_ROUND2 (CKK_NSS + 3)
1838 1861
1839 +#define CKK_NSS_CHACHA20 (CKK_NSS + 4) 1862 +#define CKK_NSS_CHACHA20 (CKK_NSS + 4)
1840 + 1863 +
1841 /* 1864 /*
1842 * NSS-defined certificate types 1865 * NSS-defined certificate types
1843 * 1866 *
1844 @@ -214,6 +216,9 @@ 1867 @@ -214,6 +216,9 @@
1845 #define CKM_NSS_TLS_KEY_AND_MAC_DERIVE_SHA256 (CKM_NSS + 23) 1868 #define CKM_NSS_TLS_KEY_AND_MAC_DERIVE_SHA256 (CKM_NSS + 23)
1846 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256 (CKM_NSS + 24) 1869 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256 (CKM_NSS + 24)
1847 1870
1848 +#define CKM_NSS_CHACHA20_KEY_GEN (CKM_NSS + 25) 1871 +#define CKM_NSS_CHACHA20_KEY_GEN (CKM_NSS + 25)
1849 +#define CKM_NSS_CHACHA20_POLY1305 (CKM_NSS + 26) 1872 +#define CKM_NSS_CHACHA20_POLY1305 (CKM_NSS + 26)
1850 + 1873 +
1851 /* 1874 /*
1852 * HISTORICAL: 1875 * HISTORICAL:
1853 * Do not attempt to use these. They are only used by NETSCAPE's internal 1876 * Do not attempt to use these. They are only used by NETSCAPE's internal
1854 @@ -281,6 +286,14 @@ 1877 @@ -281,6 +286,14 @@ typedef struct CK_NSS_MAC_CONSTANT_TIME_PARAMS {
1855 CK_ULONG ulHeaderLen; /* in */ 1878 CK_ULONG ulHeaderLen; /* in */
1856 } CK_NSS_MAC_CONSTANT_TIME_PARAMS; 1879 } CK_NSS_MAC_CONSTANT_TIME_PARAMS;
1857 1880
1858 +typedef struct CK_NSS_AEAD_PARAMS { 1881 +typedef struct CK_NSS_AEAD_PARAMS {
1859 + CK_BYTE_PTR pIv; /* This is the nonce. */ 1882 + CK_BYTE_PTR pIv; /* This is the nonce. */
1860 + CK_ULONG ulIvLen; 1883 + CK_ULONG ulIvLen;
1861 + CK_BYTE_PTR pAAD; 1884 + CK_BYTE_PTR pAAD;
1862 + CK_ULONG ulAADLen; 1885 + CK_ULONG ulAADLen;
1863 + CK_ULONG ulTagLen; 1886 + CK_ULONG ulTagLen;
1864 +} CK_NSS_AEAD_PARAMS; 1887 +} CK_NSS_AEAD_PARAMS;
1865 + 1888 +
1866 /* 1889 /*
1867 * NSS-defined return values 1890 * NSS-defined return values
1868 * 1891 *
OLDNEW
« no previous file with comments | « nss/lib/util/quickder.c ('k') | patches/nss-static.patch » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698