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