Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: crypto/p224.h

Issue 8431007: crypto: add simple P224 implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/crypto.gyp ('k') | crypto/p224.cc » ('j') | crypto/p224_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/p224.h
diff --git a/crypto/p224.h b/crypto/p224.h
new file mode 100644
index 0000000000000000000000000000000000000000..b126f735956958d159a20528a5dd5cc54124a254
--- /dev/null
+++ b/crypto/p224.h
@@ -0,0 +1,55 @@
+// 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"
+
+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 Point {
+ // Sets 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 Set(const base::StringPiece& in);
Wez 2011/11/04 22:13:46 nit: The external representation is what this acce
agl 2011/11/07 15:15:12 Went with SetFromString because FromString sounds
+
+ // ToString returns an external representation of the Point.
Wez 2011/11/04 22:13:46 nit: Consider clarifying that it's a byte-string,
agl 2011/11/07 15:15:12 Done.
+ 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 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 ScalarBaseMult(const uint8* scalar, Point* out);
+
+// Add computes *out = a+b.
+void Add(const Point& a, const Point& b, Point* out);
+
+// Negate calculates out = -a;
+void Negate(const Point& a, Point* out);
+
+} // namespace p224
+
+} // namespace crypto
+
+#endif // CRYPTO_P224_H_
« no previous file with comments | « crypto/crypto.gyp ('k') | crypto/p224.cc » ('j') | crypto/p224_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698