| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Signature stuff. | 2 * Signature stuff. |
| 3 * | 3 * |
| 4 * ***** BEGIN LICENSE BLOCK ***** | 4 * ***** BEGIN LICENSE BLOCK ***** |
| 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 6 * | 6 * |
| 7 * The contents of this file are subject to the Mozilla Public License Version | 7 * The contents of this file are subject to the Mozilla Public License Version |
| 8 * 1.1 (the "License"); you may not use this file except in compliance with | 8 * 1.1 (the "License"); you may not use this file except in compliance with |
| 9 * the License. You may obtain a copy of the License at | 9 * the License. You may obtain a copy of the License at |
| 10 * http://www.mozilla.org/MPL/ | 10 * http://www.mozilla.org/MPL/ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 * ***** END LICENSE BLOCK ***** */ | 39 * ***** END LICENSE BLOCK ***** */ |
| 40 | 40 |
| 41 #include "crypto/third_party/nss/chromium-nss.h" | 41 #include "crypto/third_party/nss/chromium-nss.h" |
| 42 | 42 |
| 43 #include <vector> | 43 #include <vector> |
| 44 | 44 |
| 45 #include <cryptohi.h> | 45 #include <cryptohi.h> |
| 46 #include <pk11pub.h> | 46 #include <pk11pub.h> |
| 47 #include <secerr.h> | 47 #include <secerr.h> |
| 48 #include <sechash.h> | 48 #include <sechash.h> |
| 49 #include <stdint.h> |
| 49 | 50 |
| 50 #include "base/basictypes.h" | |
| 51 #include "base/logging.h" | 51 #include "base/logging.h" |
| 52 #include "build/build_config.h" | 52 #include "build/build_config.h" |
| 53 | 53 |
| 54 SECStatus DerSignData(PLArenaPool *arena, | 54 SECStatus DerSignData(PLArenaPool *arena, |
| 55 SECItem *result, | 55 SECItem *result, |
| 56 SECItem *input, | 56 SECItem *input, |
| 57 SECKEYPrivateKey *key, | 57 SECKEYPrivateKey *key, |
| 58 SECOidTag algo_id) { | 58 SECOidTag algo_id) { |
| 59 if (key->keyType != ecKey) { | 59 if (key->keyType != ecKey) { |
| 60 return SEC_DerSignData(arena, result, input->data, input->len, key, | 60 return SEC_DerSignData(arena, result, input->data, input->len, key, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 81 break; | 81 break; |
| 82 case SEC_OID_ANSIX962_ECDSA_SHA512_SIGNATURE: | 82 case SEC_OID_ANSIX962_ECDSA_SHA512_SIGNATURE: |
| 83 hash_type = HASH_AlgSHA512; | 83 hash_type = HASH_AlgSHA512; |
| 84 break; | 84 break; |
| 85 default: | 85 default: |
| 86 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); | 86 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
| 87 return SECFailure; | 87 return SECFailure; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Hash the input. | 90 // Hash the input. |
| 91 std::vector<uint8> hash_data(HASH_ResultLen(hash_type)); | 91 std::vector<uint8_t> hash_data(HASH_ResultLen(hash_type)); |
| 92 SECStatus rv = HASH_HashBuf( | 92 SECStatus rv = HASH_HashBuf( |
| 93 hash_type, &hash_data[0], input->data, input->len); | 93 hash_type, &hash_data[0], input->data, input->len); |
| 94 if (rv != SECSuccess) | 94 if (rv != SECSuccess) |
| 95 return rv; | 95 return rv; |
| 96 SECItem hash = {siBuffer, &hash_data[0], | 96 SECItem hash = {siBuffer, &hash_data[0], |
| 97 static_cast<unsigned int>(hash_data.size())}; | 97 static_cast<unsigned int>(hash_data.size())}; |
| 98 | 98 |
| 99 // Compute signature of hash. | 99 // Compute signature of hash. |
| 100 int signature_len = PK11_SignatureLen(key); | 100 int signature_len = PK11_SignatureLen(key); |
| 101 std::vector<uint8> signature_data(signature_len); | 101 std::vector<uint8_t> signature_data(signature_len); |
| 102 SECItem sig = {siBuffer, &signature_data[0], | 102 SECItem sig = {siBuffer, &signature_data[0], |
| 103 static_cast<unsigned int>(signature_len)}; | 103 static_cast<unsigned int>(signature_len)}; |
| 104 rv = PK11_Sign(key, &sig, &hash); | 104 rv = PK11_Sign(key, &sig, &hash); |
| 105 if (rv != SECSuccess) | 105 if (rv != SECSuccess) |
| 106 return rv; | 106 return rv; |
| 107 | 107 |
| 108 CERTSignedData sd; | 108 CERTSignedData sd; |
| 109 PORT_Memset(&sd, 0, sizeof(sd)); | 109 PORT_Memset(&sd, 0, sizeof(sd)); |
| 110 // Fill in tbsCertificate. | 110 // Fill in tbsCertificate. |
| 111 sd.data.data = (unsigned char*) input->data; | 111 sd.data.data = (unsigned char*) input->data; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 123 sd.signature.len <<= 3; // Convert to bit string. | 123 sd.signature.len <<= 3; // Convert to bit string. |
| 124 | 124 |
| 125 // DER encode the signed data object. | 125 // DER encode the signed data object. |
| 126 void* encode_result = SEC_ASN1EncodeItem( | 126 void* encode_result = SEC_ASN1EncodeItem( |
| 127 arena, result, &sd, SEC_ASN1_GET(CERT_SignedDataTemplate)); | 127 arena, result, &sd, SEC_ASN1_GET(CERT_SignedDataTemplate)); |
| 128 | 128 |
| 129 PORT_Free(sd.signature.data); | 129 PORT_Free(sd.signature.data); |
| 130 | 130 |
| 131 return encode_result ? SECSuccess : SECFailure; | 131 return encode_result ? SECSuccess : SECFailure; |
| 132 } | 132 } |
| OLD | NEW |