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

Side by Side Diff: components/webcrypto/algorithms/util.cc

Issue 2163053002: [webcrypto] Check for empty key usages *after* key creation rather than before, to match the spec's… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/webcrypto/algorithms/util.h" 5 #include "components/webcrypto/algorithms/util.h"
6 6
7 #include <openssl/aead.h> 7 #include <openssl/aead.h>
8 #include <openssl/bn.h> 8 #include <openssl/bn.h>
9 #include <openssl/digest.h> 9 #include <openssl/digest.h>
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 size_t remainder_bits = length_bits % 8; 46 size_t remainder_bits = length_bits % 8;
47 47
48 // Zero any "unused bits" in the final byte. 48 // Zero any "unused bits" in the final byte.
49 if (remainder_bits) 49 if (remainder_bits)
50 bytes->back() &= ~((0xFF) >> remainder_bits); 50 bytes->back() &= ~((0xFF) >> remainder_bits);
51 } 51 }
52 52
53 Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages, 53 Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages,
54 blink::WebCryptoKeyUsageMask actual_usages, 54 blink::WebCryptoKeyUsageMask actual_usages) {
55 EmptyUsagePolicy empty_usage_policy) {
56 if (actual_usages == 0 &&
57 empty_usage_policy == EmptyUsagePolicy::REJECT_EMPTY) {
58 return Status::ErrorCreateKeyEmptyUsages();
59 }
60
61 if (!ContainsKeyUsages(all_possible_usages, actual_usages)) 55 if (!ContainsKeyUsages(all_possible_usages, actual_usages))
62 return Status::ErrorCreateKeyBadUsages(); 56 return Status::ErrorCreateKeyBadUsages();
63 return Status::Success(); 57 return Status::Success();
64 } 58 }
65 59
66 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, 60 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a,
67 blink::WebCryptoKeyUsageMask b) { 61 blink::WebCryptoKeyUsageMask b) {
68 return (a & b) == b; 62 return (a & b) == b;
69 } 63 }
70 64
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 additional_data.byte_length()); 111 additional_data.byte_length());
118 } 112 }
119 113
120 if (!ok) 114 if (!ok)
121 return Status::OperationError(); 115 return Status::OperationError();
122 buffer->resize(len); 116 buffer->resize(len);
123 return Status::Success(); 117 return Status::Success();
124 } 118 }
125 119
126 } // namespace webcrypto 120 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/algorithms/util.h ('k') | third_party/WebKit/LayoutTests/crypto/subtle/hkdf/exportKey-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698