| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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/hmac.h" | 5 #include "base/hmac.h" |
| 6 | 6 |
| 7 #include <nss.h> | 7 #include <nss.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 plat_->sym_key_.reset(PK11_ImportSymKey(plat_->slot_.get(), | 59 plat_->sym_key_.reset(PK11_ImportSymKey(plat_->slot_.get(), |
| 60 CKM_SHA_1_HMAC, | 60 CKM_SHA_1_HMAC, |
| 61 PK11_OriginUnwrap, | 61 PK11_OriginUnwrap, |
| 62 CKA_SIGN, | 62 CKA_SIGN, |
| 63 &key_item, | 63 &key_item, |
| 64 NULL)); | 64 NULL)); |
| 65 CHECK(plat_->sym_key_.get()); | 65 CHECK(plat_->sym_key_.get()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 HMAC::~HMAC() { | 68 HMAC::~HMAC() { |
| 69 delete plat_; | |
| 70 } | 69 } |
| 71 | 70 |
| 72 bool HMAC::Sign(const std::string& data, | 71 bool HMAC::Sign(const std::string& data, |
| 73 unsigned char* digest, | 72 unsigned char* digest, |
| 74 int digest_length) { | 73 int digest_length) { |
| 75 SECItem param = { siBuffer, NULL, 0 }; | 74 SECItem param = { siBuffer, NULL, 0 }; |
| 76 ScopedNSSContext context(PK11_CreateContextBySymKey(CKM_SHA_1_HMAC, | 75 ScopedNSSContext context(PK11_CreateContextBySymKey(CKM_SHA_1_HMAC, |
| 77 CKA_SIGN, | 76 CKA_SIGN, |
| 78 plat_->sym_key_.get(), | 77 plat_->sym_key_.get(), |
| 79 ¶m)); | 78 ¶m)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 98 if (PK11_DigestFinal(context.get(), | 97 if (PK11_DigestFinal(context.get(), |
| 99 digest, &len, digest_length) != SECSuccess) { | 98 digest, &len, digest_length) != SECSuccess) { |
| 100 NOTREACHED(); | 99 NOTREACHED(); |
| 101 return false; | 100 return false; |
| 102 } | 101 } |
| 103 | 102 |
| 104 return true; | 103 return true; |
| 105 } | 104 } |
| 106 | 105 |
| 107 } // namespace base | 106 } // namespace base |
| OLD | NEW |