summaryrefslogtreecommitdiffstats
path: root/crypto/p224.h
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-07 20:41:06 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-07 20:41:06 +0000
commit61f7c7d49965a4c231f93343622dc80db0a27515 (patch)
treead5fe9e23be0ba4f6056eb9db7e282e4871385f0 /crypto/p224.h
parent0008e75b613a252c8a5e2cca58c8376bf0e0a6a8 (diff)
downloadchromium_src-61f7c7d49965a4c231f93343622dc80db0a27515.zip
chromium_src-61f7c7d49965a4c231f93343622dc80db0a27515.tar.gz
chromium_src-61f7c7d49965a4c231f93343622dc80db0a27515.tar.bz2
Revert revert 108866 - crypto: add simple P224 implementation.
(Landed in r108866, reverted in r108869 due to shared library build issues.) git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/p224.h')
-rw-r--r--crypto/p224.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/crypto/p224.h b/crypto/p224.h
new file mode 100644
index 0000000..0b2aca9
--- /dev/null
+++ b/crypto/p224.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CRYPTO_P224_H_
+#define CRYPTO_P224_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/string_piece.h"
+#include "crypto/crypto_export.h"
+
+namespace crypto {
+
+// P224 implements an elliptic curve group, commonly known as P224 and defined
+// in FIPS 186-3, section D.2.2.
+namespace p224 {
+
+// An element of the field (ℤ/pℤ) is represented with 8, 28-bit limbs in
+// little endian order.
+typedef uint32 FieldElement[8];
+
+struct CRYPTO_EXPORT Point {
+ // SetFromString the value of the point from the 56 byte, external
+ // representation. The external point representation is an (x, y) pair of a
+ // point on the curve. Each field element is represented as a big-endian
+ // number < p.
+ bool SetFromString(const base::StringPiece& in);
+
+ // ToString returns an external representation of the Point.
+ std::string ToString() const;
+
+ // An Point is represented in Jacobian form (x/z², y/z³).
+ FieldElement x, y, z;
+};
+
+// ScalarMult computes *out = in*scalar where scalar is a 28-byte, big-endian
+// number.
+void CRYPTO_EXPORT ScalarMult(const Point& in, const uint8* scalar, Point* out);
+
+// ScalarBaseMult computes *out = g*scalar where g is the base point of the
+// curve and scalar is a 28-byte, big-endian number.
+void CRYPTO_EXPORT ScalarBaseMult(const uint8* scalar, Point* out);
+
+// Add computes *out = a+b.
+void CRYPTO_EXPORT Add(const Point& a, const Point& b, Point* out);
+
+// Negate calculates out = -a;
+void CRYPTO_EXPORT Negate(const Point& a, Point* out);
+
+} // namespace p224
+
+} // namespace crypto
+
+#endif // CRYPTO_P224_H_