| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "crypto/signature_verifier.h" | 5 #include "crypto/signature_verifier.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "crypto/cssm_init.h" | 10 #include "crypto/cssm_init.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SignatureVerifier::VerifyUpdate(const uint8* data_part, | 71 void SignatureVerifier::VerifyUpdate(const uint8* data_part, |
| 72 int data_part_len) { | 72 int data_part_len) { |
| 73 CSSM_DATA data; | 73 CSSM_DATA data; |
| 74 data.Data = const_cast<uint8*>(data_part); | 74 data.Data = const_cast<uint8*>(data_part); |
| 75 data.Length = data_part_len; | 75 data.Length = data_part_len; |
| 76 CSSM_RETURN crtn = CSSM_VerifyDataUpdate(sig_handle_, &data, 1); | 76 CSSM_RETURN crtn = CSSM_VerifyDataUpdate(sig_handle_, &data, 1); |
| 77 DCHECK(crtn == CSSM_OK); | 77 DCHECK_EQ(CSSM_OK, crtn); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool SignatureVerifier::VerifyFinal() { | 80 bool SignatureVerifier::VerifyFinal() { |
| 81 CSSM_DATA sig; | 81 CSSM_DATA sig; |
| 82 sig.Data = const_cast<uint8*>(&signature_[0]); | 82 sig.Data = const_cast<uint8*>(&signature_[0]); |
| 83 sig.Length = signature_.size(); | 83 sig.Length = signature_.size(); |
| 84 CSSM_RETURN crtn = CSSM_VerifyDataFinal(sig_handle_, &sig); | 84 CSSM_RETURN crtn = CSSM_VerifyDataFinal(sig_handle_, &sig); |
| 85 Reset(); | 85 Reset(); |
| 86 | 86 |
| 87 // crtn is CSSMERR_CSP_VERIFY_FAILED if signature verification fails. | 87 // crtn is CSSMERR_CSP_VERIFY_FAILED if signature verification fails. |
| 88 return (crtn == CSSM_OK); | 88 return (crtn == CSSM_OK); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void SignatureVerifier::Reset() { | 91 void SignatureVerifier::Reset() { |
| 92 CSSM_RETURN crtn; | 92 CSSM_RETURN crtn; |
| 93 if (sig_handle_) { | 93 if (sig_handle_) { |
| 94 crtn = CSSM_DeleteContext(sig_handle_); | 94 crtn = CSSM_DeleteContext(sig_handle_); |
| 95 DCHECK(crtn == CSSM_OK); | 95 DCHECK_EQ(CSSM_OK, crtn); |
| 96 sig_handle_ = 0; | 96 sig_handle_ = 0; |
| 97 } | 97 } |
| 98 signature_.clear(); | 98 signature_.clear(); |
| 99 | 99 |
| 100 // Can't call CSSM_FreeKey on public_key_ because we constructed | 100 // Can't call CSSM_FreeKey on public_key_ because we constructed |
| 101 // public_key_ manually. | 101 // public_key_ manually. |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace crypto | 104 } // namespace crypto |
| 105 | 105 |
| OLD | NEW |