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 <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/string_piece.h" | |
13 | |
14 namespace crypto { | |
15 | |
16 // P224 implements an elliptic curve group, commonly known as P224 and defined | |
17 // in FIPS 186-3, section D.2.2. | |
18 namespace p224 { | |
19 | |
20 // An element of the field (ℤ/pℤ) is represented with 8, 28-bit limbs in | |
21 // little endian order. | |
22 typedef uint32 FieldElement[8]; | |
23 | |
24 struct Point { | |
25 // Sets the value of the point from the 56 byte, external representation. The | |
26 // external point representation is an (x, y) pair of a point on the curve. | |
27 // Each field element is represented as a big-endian number < p. | |
28 bool Set(const base::StringPiece& in); | |
Wez
2011/11/04 22:13:46
nit: The external representation is what this acce
agl
2011/11/07 15:15:12
Went with SetFromString because FromString sounds
| |
29 | |
30 // ToString returns an external representation of the Point. | |
Wez
2011/11/04 22:13:46
nit: Consider clarifying that it's a byte-string,
agl
2011/11/07 15:15:12
Done.
| |
31 std::string ToString() const; | |
32 | |
33 // An Point is represented in Jacobian form (x/z², y/z³). | |
34 FieldElement x, y, z; | |
35 }; | |
36 | |
37 // ScalarMult computes *out = in*scalar where scalar is a 28-byte, big-endian | |
38 // number. | |
39 void ScalarMult(const Point& in, const uint8* scalar, Point* out); | |
40 | |
41 // ScalarBaseMult computes *out = g*scalar where g is the base point of the | |
42 // curve and scalar is a 28-byte, big-endian number. | |
43 void ScalarBaseMult(const uint8* scalar, Point* out); | |
44 | |
45 // Add computes *out = a+b. | |
46 void Add(const Point& a, const Point& b, Point* out); | |
47 | |
48 // Negate calculates out = -a; | |
49 void Negate(const Point& a, Point* out); | |
50 | |
51 } // namespace p224 | |
52 | |
53 } // namespace crypto | |
54 | |
55 #endif // CRYPTO_P224_H_ | |
OLD | NEW |