OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CRYPTO_P224_H_ | |
6 #define CRYPTO_P224_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 | |
11 namespace crypto { | |
12 | |
13 // P224 implements an elliptic curve group, commonly known as P224 and defined | |
14 // in FIPS 186-3, section D.2.2. | |
15 class P224 { | |
16 public: | |
17 struct ExternalPoint { | |
18 // The external point representation is an (x, y) pair of a point on the | |
19 // curve. Each field element is represented as a big-endian number < p. | |
20 uint8 affine[2 * 28]; | |
21 }; | |
22 | |
23 // An element of the field (ℤ/pℤ) is represented with 8, 28-bit limbs in | |
24 // little endian order. | |
25 typedef uint32 FieldElement[8]; | |
26 | |
27 struct InternalPoint { | |
28 // An InternalPoint is represented in Jacobian form (x/z², y/z³). | |
29 FieldElement x, y, z; | |
30 }; | |
31 | |
32 // ToInternal converts a point from external to internal representation. It | |
33 // verifies that the external point actually lies of the curve and returns | |
34 // true if so. | |
35 static bool ToInternal(const ExternalPoint& in, InternalPoint* out); | |
Wez
2011/11/02 23:46:06
Why is this a member of P224, rather than of P224:
agl
2011/11/03 17:20:49
I'm not sure that I like it, but meh. Have changed
| |
36 | |
37 // ToExternal converts an internal point to an external point. | |
38 static void ToExternal(const InternalPoint& in, ExternalPoint* out); | |
Wez
2011/11/02 23:46:06
Similarly here.
agl
2011/11/03 17:20:49
Done.
| |
39 | |
40 // ScalarMult computes *out = in*scalar where scalar is a big-endian number. | |
Wez
2011/11/02 23:46:06
What format is |scalar| in, besides being big-endi
agl
2011/11/03 17:20:49
None. It's just a big-endian number.
Wez
2011/11/03 20:03:46
But it has to be 224 bits == 28 bytes of big-endia
agl
2011/11/04 20:13:22
Oh, I see. Actually no, it could be shorter but si
| |
41 static void ScalarMult(const InternalPoint& in, const uint8* scalar, | |
42 InternalPoint* out); | |
Wez
2011/11/02 23:46:06
According to style, this should be MultiplyByScala
agl
2011/11/03 17:20:49
ScalarMult is a name taken from EBATS: a standard
Wez
2011/11/03 20:03:46
OK, I wondered if that might be the case. I think
| |
43 | |
44 // ScalarBaseMult computes *out = g*scalar where g is the base point of the | |
45 // curve. | |
46 static void ScalarBaseMult(const uint8* scalar, InternalPoint* out); | |
47 | |
48 // Add computes *out = a+b. | |
49 static void Add(const InternalPoint& a, const InternalPoint& b, | |
50 InternalPoint* out); | |
51 | |
52 // Negate calculates out = -a; | |
53 static void Negate(const InternalPoint& a, InternalPoint* out); | |
54 }; | |
55 | |
56 } // namespace crypto | |
57 | |
58 #endif // CRYPTO_P224_H_ | |
OLD | NEW |