Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is an implementation of the P224 elliptic curve group. It's written to | 5 // This is an implementation of the P224 elliptic curve group. It's written to |
| 6 // be short and simple rather than fast, although it's still constant-time. | 6 // be short and simple rather than fast, although it's still constant-time. |
| 7 // | 7 // |
| 8 // See http://www.imperialviolet.org/2010/12/04/ecc.html ([1]) for background. | 8 // See http://www.imperialviolet.org/2010/12/04/ecc.html ([1]) for background. |
| 9 | 9 |
| 10 #include "crypto/p224.h" | 10 #include "crypto/p224.h" |
| 11 | 11 |
| 12 #include <string.h> | 12 #include <string.h> |
| 13 | 13 |
| 14 #include "base/sys_byteorder.h" | 14 #include "base/sys_byteorder.h" |
| 15 | 15 |
| 16 #if defined(OS_WIN) | |
| 17 // Allow htonl/ntohl to be called without requiring ws2_32.dll to be loaded, | |
| 18 // which isn't available in Chrome's sandbox. See crbug.com/116591. | |
| 19 #define ntohl(x) _byteswap_ulong(x) | |
| 20 #define htonl(x) _byteswap_ulong(x) | |
| 21 #endif // OS_WIN | |
|
Ryan Sleevi
2012/03/06 01:56:47
This is the second or third time I've seen this pa
| |
| 22 | |
| 23 | |
| 24 | |
| 16 namespace { | 25 namespace { |
| 17 | 26 |
| 18 // Field element functions. | 27 // Field element functions. |
| 19 // | 28 // |
| 20 // The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1. | 29 // The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1. |
| 21 // | 30 // |
| 22 // Field elements are represented by a FieldElement, which is a typedef to an | 31 // Field elements are represented by a FieldElement, which is a typedef to an |
| 23 // array of 8 uint32's. The value of a FieldElement, a, is: | 32 // array of 8 uint32's. The value of a FieldElement, a, is: |
| 24 // a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7] | 33 // a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7] |
| 25 // | 34 // |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 Subtract(&out->y, kP, y); | 678 Subtract(&out->y, kP, y); |
| 670 Reduce(&out->y); | 679 Reduce(&out->y); |
| 671 | 680 |
| 672 memset(&out->z, 0, sizeof(out->z)); | 681 memset(&out->z, 0, sizeof(out->z)); |
| 673 out->z[0] = 1; | 682 out->z[0] = 1; |
| 674 } | 683 } |
| 675 | 684 |
| 676 } // namespace p224 | 685 } // namespace p224 |
| 677 | 686 |
| 678 } // namespace crypto | 687 } // namespace crypto |
| OLD | NEW |