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 3 // found in the LICENSE file. 4 5 #ifndef CRYPTO_P224_H_ 6 #define CRYPTO_P224_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include <string> 12 13 #include "base/strings/string_piece.h" 14 #include "crypto/crypto_export.h" 15 16 namespace crypto { 17 18 // P224 implements an elliptic curve group, commonly known as P224 and defined 19 // in FIPS 186-3, section D.2.2. 20 namespace p224 { 21 22 // An element of the field (ℤ/pℤ) is represented with 8, 28-bit limbs in 23 // little endian order. 24 typedef uint32_t FieldElement[8]; 25 26 struct CRYPTO_EXPORT Point { 27 // SetFromString the value of the point from the 56 byte, external 28 // representation. The external point representation is an (x, y) pair of a 29 // point on the curve. Each field element is represented as a big-endian 30 // number < p. 31 bool SetFromString(const base::StringPiece& in); 32 33 // ToString returns an external representation of the Point. 34 std::string ToString() const; 35 36 // An Point is represented in Jacobian form (x/z², y/z³). 37 FieldElement x, y, z; 38 }; 39 40 // kScalarBytes is the number of bytes needed to represent an element of the 41 // P224 field. 42 static const size_t kScalarBytes = 28; 43 44 // ScalarMult computes *out = in*scalar where scalar is a 28-byte, big-endian 45 // number. 46 void CRYPTO_EXPORT ScalarMult(const Point& in, 47 const uint8_t* scalar, 48 Point* out); 49 50 // ScalarBaseMult computes *out = g*scalar where g is the base point of the 51 // curve and scalar is a 28-byte, big-endian number. 52 void CRYPTO_EXPORT ScalarBaseMult(const uint8_t* scalar, Point* out); 53 54 // Add computes *out = a+b. 55 void CRYPTO_EXPORT Add(const Point& a, const Point& b, Point* out); 56 57 // Negate calculates out = -a; 58 void CRYPTO_EXPORT Negate(const Point& a, Point* out); 59 60 } // namespace p224 61 62 } // namespace crypto 63 64 #endif // CRYPTO_P224_H_ 65