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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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> 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], hash_data.size()}; | 96 SECItem hash = {siBuffer, &hash_data[0], |
| 97 » » static_cast<unsigned int>(hash_data.size())}; |
97 | 98 |
98 // Compute signature of hash. | 99 // Compute signature of hash. |
99 int signature_len = PK11_SignatureLen(key); | 100 int signature_len = PK11_SignatureLen(key); |
100 std::vector<uint8> signature_data(signature_len); | 101 std::vector<uint8> signature_data(signature_len); |
101 SECItem sig = {siBuffer, &signature_data[0], signature_len}; | 102 SECItem sig = {siBuffer, &signature_data[0], |
| 103 » » static_cast<unsigned int>(signature_len)}; |
102 rv = PK11_Sign(key, &sig, &hash); | 104 rv = PK11_Sign(key, &sig, &hash); |
103 if (rv != SECSuccess) | 105 if (rv != SECSuccess) |
104 return rv; | 106 return rv; |
105 | 107 |
106 CERTSignedData sd; | 108 CERTSignedData sd; |
107 PORT_Memset(&sd, 0, sizeof(sd)); | 109 PORT_Memset(&sd, 0, sizeof(sd)); |
108 // Fill in tbsCertificate. | 110 // Fill in tbsCertificate. |
109 sd.data.data = (unsigned char*) input->data; | 111 sd.data.data = (unsigned char*) input->data; |
110 sd.data.len = input->len; | 112 sd.data.len = input->len; |
111 | 113 |
112 // Fill in signatureAlgorithm. | 114 // Fill in signatureAlgorithm. |
113 rv = SECOID_SetAlgorithmID(arena, &sd.signatureAlgorithm, algo_id, 0); | 115 rv = SECOID_SetAlgorithmID(arena, &sd.signatureAlgorithm, algo_id, 0); |
114 if (rv != SECSuccess) | 116 if (rv != SECSuccess) |
115 return rv; | 117 return rv; |
116 | 118 |
117 // Fill in signatureValue. | 119 // Fill in signatureValue. |
118 rv = DSAU_EncodeDerSigWithLen(&sd.signature, &sig, sig.len); | 120 rv = DSAU_EncodeDerSigWithLen(&sd.signature, &sig, sig.len); |
119 if (rv != SECSuccess) | 121 if (rv != SECSuccess) |
120 return rv; | 122 return rv; |
121 sd.signature.len <<= 3; // Convert to bit string. | 123 sd.signature.len <<= 3; // Convert to bit string. |
122 | 124 |
123 // DER encode the signed data object. | 125 // DER encode the signed data object. |
124 void* encode_result = SEC_ASN1EncodeItem( | 126 void* encode_result = SEC_ASN1EncodeItem( |
125 arena, result, &sd, SEC_ASN1_GET(CERT_SignedDataTemplate)); | 127 arena, result, &sd, SEC_ASN1_GET(CERT_SignedDataTemplate)); |
126 | 128 |
127 PORT_Free(sd.signature.data); | 129 PORT_Free(sd.signature.data); |
128 | 130 |
129 return encode_result ? SECSuccess : SECFailure; | 131 return encode_result ? SECSuccess : SECFailure; |
130 } | 132 } |
OLD | NEW |