| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "crypto/crypto_export.h" | 6 #include "crypto/crypto_export.h" |
| 7 | 7 |
| 8 namespace crypto { | 8 namespace crypto { |
| 9 | 9 |
| 10 // GaloisHash implements the polynomial authenticator part of GCM as specified | 10 // GaloisHash implements the polynomial authenticator part of GCM as specified |
| 11 // in http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm
-revised-spec.pdf | 11 // in http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm
-revised-spec.pdf |
| 12 // Specifically it implements the GHASH function, defined in section 2.3 of | 12 // Specifically it implements the GHASH function, defined in section 2.3 of |
| 13 // that document. | 13 // that document. |
| 14 // | 14 // |
| 15 // In SP-800-38D, GHASH is defined differently and takes only a single data | 15 // In SP-800-38D, GHASH is defined differently and takes only a single data |
| 16 // argument. But it is always called with an argument of a certain form: | 16 // argument. But it is always called with an argument of a certain form: |
| 17 // GHASH_H (A || 0^v || C || 0^u || [len(A)]_64 || [len(C)]_64) | 17 // GHASH_H (A || 0^v || C || 0^u || [len(A)]_64 || [len(C)]_64) |
| 18 // This mirrors how the gcm-revised-spec.pdf version of GHASH handles its two | 18 // This mirrors how the gcm-revised-spec.pdf version of GHASH handles its two |
| 19 // data arguments. The two GHASH functions therefore differ only in whether the | 19 // data arguments. The two GHASH functions therefore differ only in whether the |
| 20 // data is formatted inside or outside of the function. | 20 // data is formatted inside or outside of the function. |
| 21 // | 21 // |
| 22 // WARNING: do not use this as a generic authenticator. Polynomial | 22 // WARNING: do not use this as a generic authenticator. Polynomial |
| 23 // authenticators must be used in the correct manner and any use outside of GCM | 23 // authenticators must be used in the correct manner and any use outside of GCM |
| 24 // requires careful consideration. | 24 // requires careful consideration. |
| 25 // | 25 // |
| 26 // WARNING: this code is not constant time. However, in all likelihood, nor is | 26 // WARNING: this code is not constant time. However, in all likelihood, nor is |
| 27 // the implementation of AES that is used. | 27 // the implementation of AES that is used. |
| 28 class CRYPTO_EXPORT_PRIVATE GaloisHash { | 28 class CRYPTO_EXPORT GaloisHash { |
| 29 public: | 29 public: |
| 30 explicit GaloisHash(const uint8 key[16]); | 30 explicit GaloisHash(const uint8 key[16]); |
| 31 | 31 |
| 32 // Reset prepares to digest a fresh message with the same key. This is more | 32 // Reset prepares to digest a fresh message with the same key. This is more |
| 33 // efficient than creating a fresh object. | 33 // efficient than creating a fresh object. |
| 34 void Reset(); | 34 void Reset(); |
| 35 | 35 |
| 36 // UpdateAdditional hashes in `additional' data. This is data that is not | 36 // UpdateAdditional hashes in `additional' data. This is data that is not |
| 37 // encrypted, but is covered by the authenticator. All additional data must | 37 // encrypted, but is covered by the authenticator. All additional data must |
| 38 // be written before any ciphertext is written. | 38 // be written before any ciphertext is written. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 FieldElement y_; | 77 FieldElement y_; |
| 78 State state_; | 78 State state_; |
| 79 size_t additional_bytes_; | 79 size_t additional_bytes_; |
| 80 size_t ciphertext_bytes_; | 80 size_t ciphertext_bytes_; |
| 81 uint8 buf_[16]; | 81 uint8 buf_[16]; |
| 82 size_t buf_used_; | 82 size_t buf_used_; |
| 83 FieldElement product_table_[16]; | 83 FieldElement product_table_[16]; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 } // namespace crypto | 86 } // namespace crypto |
| OLD | NEW |