Home | History | Annotate | Download | only in crypto
      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 <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/strings/string_piece.h"
     12 #include "crypto/crypto_export.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 CRYPTO_EXPORT Point {
     25   // SetFromString the value of the point from the 56 byte, external
     26   // representation. The external point representation is an (x, y) pair of a
     27   // point on the curve. Each field element is represented as a big-endian
     28   // number < p.
     29   bool SetFromString(const base::StringPiece& in);
     30 
     31   // ToString returns an external representation of the Point.
     32   std::string ToString() const;
     33 
     34   // An Point is represented in Jacobian form (x/z, y/z).
     35   FieldElement x, y, z;
     36 };
     37 
     38 // kScalarBytes is the number of bytes needed to represent an element of the
     39 // P224 field.
     40 static const size_t kScalarBytes = 28;
     41 
     42 // ScalarMult computes *out = in*scalar where scalar is a 28-byte, big-endian
     43 // number.
     44 void CRYPTO_EXPORT ScalarMult(const Point& in, const uint8* scalar, Point* out);
     45 
     46 // ScalarBaseMult computes *out = g*scalar where g is the base point of the
     47 // curve and scalar is a 28-byte, big-endian number.
     48 void CRYPTO_EXPORT ScalarBaseMult(const uint8* scalar, Point* out);
     49 
     50 // Add computes *out = a+b.
     51 void CRYPTO_EXPORT Add(const Point& a, const Point& b, Point* out);
     52 
     53 // Negate calculates out = -a;
     54 void CRYPTO_EXPORT Negate(const Point& a, Point* out);
     55 
     56 }  // namespace p224
     57 
     58 }  // namespace crypto
     59 
     60 #endif  // CRYPTO_P224_H_
     61