chromeos: bluetooth: add BluetoothNodeClient
[chromium-blink-merge.git] / crypto / p224.h
blob412ca9990583046b545e8d2b47b6f3186260e67a
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.
5 #ifndef CRYPTO_P224_H_
6 #define CRYPTO_P224_H_
7 #pragma once
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/string_piece.h"
13 #include "crypto/crypto_export.h"
15 namespace crypto {
17 // P224 implements an elliptic curve group, commonly known as P224 and defined
18 // in FIPS 186-3, section D.2.2.
19 namespace p224 {
21 // An element of the field (ℤ/pℤ) is represented with 8, 28-bit limbs in
22 // little endian order.
23 typedef uint32 FieldElement[8];
25 struct CRYPTO_EXPORT 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);
32 // ToString returns an external representation of the Point.
33 std::string ToString() const;
35 // An Point is represented in Jacobian form (x/z², y/z³).
36 FieldElement x, y, z;
39 // kScalarBytes is the number of bytes needed to represent an element of the
40 // P224 field.
41 static const size_t kScalarBytes = 28;
43 // ScalarMult computes *out = in*scalar where scalar is a 28-byte, big-endian
44 // number.
45 void CRYPTO_EXPORT ScalarMult(const Point& in, const uint8* scalar, Point* out);
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.
49 void CRYPTO_EXPORT ScalarBaseMult(const uint8* scalar, Point* out);
51 // Add computes *out = a+b.
52 void CRYPTO_EXPORT Add(const Point& a, const Point& b, Point* out);
54 // Negate calculates out = -a;
55 void CRYPTO_EXPORT Negate(const Point& a, Point* out);
57 } // namespace p224
59 } // namespace crypto
61 #endif // CRYPTO_P224_H_