| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 14 #include "base/sys_byteorder.h" |
| 15 | |
| 16 // For htonl and ntohl. | |
| 17 #if defined(OS_WIN) | |
| 18 #include <winsock2.h> | |
| 19 #else | |
| 20 #include <arpa/inet.h> | |
| 21 #endif | |
| 22 | 15 |
| 23 namespace { | 16 namespace { |
| 24 | 17 |
| 25 // Field element functions. | 18 // Field element functions. |
| 26 // | 19 // |
| 27 // The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1. | 20 // The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1. |
| 28 // | 21 // |
| 29 // Field elements are represented by a FieldElement, which is a typedef to an | 22 // Field elements are represented by a FieldElement, which is a typedef to an |
| 30 // array of 8 uint32's. The value of a FieldElement, a, is: | 23 // array of 8 uint32's. The value of a FieldElement, a, is: |
| 31 // a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7] | 24 // a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7] |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 Subtract(&out->y, kP, y); | 636 Subtract(&out->y, kP, y); |
| 644 Reduce(&out->y); | 637 Reduce(&out->y); |
| 645 | 638 |
| 646 memset(&out->z, 0, sizeof(out->z)); | 639 memset(&out->z, 0, sizeof(out->z)); |
| 647 out->z[0] = 1; | 640 out->z[0] = 1; |
| 648 } | 641 } |
| 649 | 642 |
| 650 } // namespace p224 | 643 } // namespace p224 |
| 651 | 644 |
| 652 } // namespace crypto | 645 } // namespace crypto |
| OLD | NEW |