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

Side by Side Diff: crypto/ghash.h

Issue 11175015: crypto: add GHASH implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 8 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "base/basictypes.h"
6
7 namespace crypto {
8
9 // GaliosHash implements the polynomial authenticator part of GCM as specified
wtc 2012/10/19 21:35:22 Typo: Galios => Galois
agl 2012/10/22 21:50:56 Done.
10 // in http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
11 // Specifically it implements the GHASH function, defined in section 6.4 of
wtc 2012/10/19 21:35:22 Since your GaliosHash function hashes the lengths
agl 2012/10/22 21:50:56 Both the original paper and SP-800-38D produce the
12 // that document.
13 //
14 // WARNING: do not use this as a generic authenticator. Polynomial
15 // authenticators must be used in the correct manner and any use outside of GCM
16 // requires careful consideration.
17 //
18 // WARNING: this code is not constant time. However, in all likelihood, nor is
19 // the implementation of AES that is used.
20 class GaliosHash {
21 public:
22 explicit GaliosHash(const uint8 key[16]);
23
24 // Reset prepares to digest a fresh message with the same key. This is more
25 // efficient than creating a fresh object.
26 void Reset();
27
28 // UpdateAdditional hashes in `additional' data. This is data that is not
29 // encrypted, but is covered by the authenticator. All additional data must
30 // be written before any ciphertext is written.
31 void UpdateAdditional(const uint8* data, size_t length);
32
33 // UpdateCiphertext hashes in ciphertext to be authenticated.
34 void UpdateCiphertext(const uint8* data, size_t length);
35
36 // Digest finishes the hash computation and writes the result into |result|.
37 void Digest(uint8 result[16]);
wtc 2012/10/19 21:35:22 This method should probably be named Finish(), wit
agl 2012/10/22 21:50:56 Done.
38
39 private:
40 enum State {
41 kHashingAdditionalData,
42 kHashingCiphertext,
43 kComplete,
44 };
45
46 struct FieldElement {
47 uint64 low, hi;
48 };
49
50 // Add returns |x|+|y|.
51 static FieldElement Add(const FieldElement& x, const FieldElement& y);
52 // Double returns 2*|x|.
53 static FieldElement Double(const FieldElement& x);
54 // MulAfterPrecomputation sets |x| = |x|*h where h is |table[1]| and
55 // table[i] = i*h for i=0..15.
56 static void MulAfterPrecomputation(const FieldElement* table,
57 FieldElement* x);
58 // Mul16 sets |x| = 16*|x|.
59 static void Mul16(FieldElement* x);
60
61 // UpdateBlocks processes |num_blocks| 16-bytes blocks from |bytes|.
62 void UpdateBlocks(const uint8* bytes, size_t num_blocks);
63 void Update(const uint8* bytes, size_t length);
wtc 2012/10/19 21:35:22 Nit: document Update().
agl 2012/10/22 21:50:56 Done.
64
65 FieldElement y_;
66 State state_;
67 size_t additional_bytes_;
68 size_t ciphertext_bytes_;
69 uint8 buf_[16];
70 size_t buf_used_;
71 FieldElement productTable[16];
wtc 2012/10/19 21:35:22 productTable => product_table_ Note the trailing
agl 2012/10/22 21:50:56 Done.
72 };
73
74 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/crypto.gyp ('k') | crypto/ghash.cc » ('j') | crypto/ghash.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698