| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 /* | 4 /* |
| 5 * This file implements the Symkey wrapper and the PKCS context | 5 * This file implements the Symkey wrapper and the PKCS context |
| 6 * Interfaces. | 6 * Interfaces. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "seccomon.h" | 9 #include "seccomon.h" |
| 10 #include "secmod.h" | 10 #include "secmod.h" |
| (...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 attrs++; | 1670 attrs++; |
| 1671 PK11_SETATTRS(attrs, operation, &cktrue, 1); attrs++; | 1671 PK11_SETATTRS(attrs, operation, &cktrue, 1); attrs++; |
| 1672 PK11_SETATTRS(attrs, CKA_VALUE_LEN, &key_size, sizeof(key_size)); | 1672 PK11_SETATTRS(attrs, CKA_VALUE_LEN, &key_size, sizeof(key_size)); |
| 1673 attrs++; | 1673 attrs++; |
| 1674 templateCount = attrs - keyTemplate; | 1674 templateCount = attrs - keyTemplate; |
| 1675 PR_ASSERT(templateCount <= sizeof(keyTemplate)/sizeof(CK_ATTRIBUTE))
; | 1675 PR_ASSERT(templateCount <= sizeof(keyTemplate)/sizeof(CK_ATTRIBUTE))
; |
| 1676 | 1676 |
| 1677 keyType = PK11_GetKeyType(target,keySize); | 1677 keyType = PK11_GetKeyType(target,keySize); |
| 1678 key_size = keySize; | 1678 key_size = keySize; |
| 1679 if (key_size == 0) { | 1679 if (key_size == 0) { |
| 1680 » » if (pk11_GetPredefinedKeyLength(keyType)) { | 1680 » » if ((key_size = pk11_GetPredefinedKeyLength(keyType))) { |
| 1681 templateCount --; | 1681 templateCount --; |
| 1682 } else { | 1682 } else { |
| 1683 /* sigh, some tokens can't figure this out and require | 1683 /* sigh, some tokens can't figure this out and require |
| 1684 * CKA_VALUE_LEN to be set */ | 1684 * CKA_VALUE_LEN to be set */ |
| 1685 key_size = SHA1_LENGTH; | 1685 key_size = SHA1_LENGTH; |
| 1686 } | 1686 } |
| 1687 } | 1687 } |
| 1688 symKey->size = key_size; | 1688 symKey->size = key_size; |
| 1689 | 1689 |
| 1690 mechParams = PORT_ZNew(CK_ECDH1_DERIVE_PARAMS); | 1690 mechParams = PORT_ZNew(CK_ECDH1_DERIVE_PARAMS); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 CK_ULONG key_size = 0; | 1755 CK_ULONG key_size = 0; |
| 1756 CK_ATTRIBUTE keyTemplate[4]; | 1756 CK_ATTRIBUTE keyTemplate[4]; |
| 1757 int templateCount; | 1757 int templateCount; |
| 1758 CK_ATTRIBUTE *attrs = keyTemplate; | 1758 CK_ATTRIBUTE *attrs = keyTemplate; |
| 1759 CK_ECDH1_DERIVE_PARAMS *mechParams = NULL; | 1759 CK_ECDH1_DERIVE_PARAMS *mechParams = NULL; |
| 1760 | 1760 |
| 1761 if (pubKey->keyType != ecKey) { | 1761 if (pubKey->keyType != ecKey) { |
| 1762 PORT_SetError(SEC_ERROR_BAD_KEY); | 1762 PORT_SetError(SEC_ERROR_BAD_KEY); |
| 1763 return NULL; | 1763 return NULL; |
| 1764 } | 1764 } |
| 1765 if ((kdf < CKD_NULL) || (kdf > CKD_SHA1_KDF)) { | 1765 if ((kdf != CKD_NULL) && (kdf != CKD_SHA1_KDF) && |
| 1766 » (kdf != CKD_SHA224_KDF) && (kdf != CKD_SHA256_KDF) && |
| 1767 » (kdf != CKD_SHA384_KDF) && (kdf != CKD_SHA512_KDF)) { |
| 1766 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); | 1768 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
| 1767 return NULL; | 1769 return NULL; |
| 1768 } | 1770 } |
| 1769 | 1771 |
| 1770 /* get our key Structure */ | 1772 /* get our key Structure */ |
| 1771 symKey = pk11_CreateSymKey(slot, target, PR_TRUE, PR_TRUE, wincx); | 1773 symKey = pk11_CreateSymKey(slot, target, PR_TRUE, PR_TRUE, wincx); |
| 1772 if (symKey == NULL) { | 1774 if (symKey == NULL) { |
| 1773 return NULL; | 1775 return NULL; |
| 1774 } | 1776 } |
| 1775 | 1777 |
| 1776 symKey->origin = PK11_OriginDerive; | 1778 symKey->origin = PK11_OriginDerive; |
| 1777 | 1779 |
| 1778 PK11_SETATTRS(attrs, CKA_CLASS, &keyClass, sizeof(keyClass)); attrs++; | 1780 PK11_SETATTRS(attrs, CKA_CLASS, &keyClass, sizeof(keyClass)); attrs++; |
| 1779 PK11_SETATTRS(attrs, CKA_KEY_TYPE, &keyType, sizeof(keyType)); attrs++; | 1781 PK11_SETATTRS(attrs, CKA_KEY_TYPE, &keyType, sizeof(keyType)); attrs++; |
| 1780 PK11_SETATTRS(attrs, operation, &cktrue, 1); attrs++; | 1782 PK11_SETATTRS(attrs, operation, &cktrue, 1); attrs++; |
| 1781 PK11_SETATTRS(attrs, CKA_VALUE_LEN, &key_size, sizeof(key_size)); attrs++; | 1783 PK11_SETATTRS(attrs, CKA_VALUE_LEN, &key_size, sizeof(key_size)); attrs++; |
| 1782 templateCount = attrs - keyTemplate; | 1784 templateCount = attrs - keyTemplate; |
| 1783 PR_ASSERT(templateCount <= sizeof(keyTemplate)/sizeof(CK_ATTRIBUTE)); | 1785 PR_ASSERT(templateCount <= sizeof(keyTemplate)/sizeof(CK_ATTRIBUTE)); |
| 1784 | 1786 |
| 1785 keyType = PK11_GetKeyType(target,keySize); | 1787 keyType = PK11_GetKeyType(target,keySize); |
| 1786 key_size = keySize; | 1788 key_size = keySize; |
| 1787 if (key_size == 0) { | 1789 if (key_size == 0) { |
| 1788 » if (pk11_GetPredefinedKeyLength(keyType)) { | 1790 » if ((key_size = pk11_GetPredefinedKeyLength(keyType))) { |
| 1789 templateCount --; | 1791 templateCount --; |
| 1790 } else { | 1792 } else { |
| 1791 /* sigh, some tokens can't figure this out and require | 1793 /* sigh, some tokens can't figure this out and require |
| 1792 * CKA_VALUE_LEN to be set */ | 1794 * CKA_VALUE_LEN to be set */ |
| 1793 switch (kdf) { | 1795 switch (kdf) { |
| 1794 case CKD_NULL: | 1796 case CKD_NULL: |
| 1795 » » key_size = (pubKey->u.ec.publicValue.len-1)/2; | 1797 » » if (pubKey->u.ec.publicValue.data[0] == 0x04) { |
| 1798 » » /* key encoded in uncompressed form */ |
| 1799 » » key_size = (pubKey->u.ec.publicValue.len-1)/2; |
| 1800 » » } else if ((pubKey->u.ec.publicValue.data[0] == 0x02) || |
| 1801 » » » (pubKey->u.ec.publicValue.data[0] == 0x03)) { |
| 1802 » » /* key encoded in compressed form */ |
| 1803 » » key_size = pubKey->u.ec.publicValue.len-1; |
| 1804 » » } else { |
| 1805 » » /* key encoding not recognized */ |
| 1806 » » PK11_FreeSymKey(symKey); |
| 1807 » » return NULL; |
| 1808 » » } |
| 1796 break; | 1809 break; |
| 1797 case CKD_SHA1_KDF: | 1810 case CKD_SHA1_KDF: |
| 1798 key_size = SHA1_LENGTH; | 1811 key_size = SHA1_LENGTH; |
| 1799 break; | 1812 break; |
| 1813 case CKD_SHA224_KDF: |
| 1814 key_size = SHA224_LENGTH; |
| 1815 break; |
| 1816 case CKD_SHA256_KDF: |
| 1817 key_size = SHA256_LENGTH; |
| 1818 break; |
| 1819 case CKD_SHA384_KDF: |
| 1820 key_size = SHA384_LENGTH; |
| 1821 break; |
| 1822 case CKD_SHA512_KDF: |
| 1823 key_size = SHA512_LENGTH; |
| 1824 break; |
| 1800 default: | 1825 default: |
| 1801 PORT_Assert(!"Invalid CKD"); | 1826 PORT_Assert(!"Invalid CKD"); |
| 1802 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); | 1827 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
| 1803 return NULL; | 1828 return NULL; |
| 1804 } | 1829 } |
| 1805 } | 1830 } |
| 1806 } | 1831 } |
| 1807 symKey->size = key_size; | 1832 symKey->size = key_size; |
| 1808 | 1833 |
| 1809 mechParams = PORT_ZNew(CK_ECDH1_DERIVE_PARAMS); | 1834 mechParams = PORT_ZNew(CK_ECDH1_DERIVE_PARAMS); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2314 PK11_ExitSlotMonitor(symKey->slot); | 2339 PK11_ExitSlotMonitor(symKey->slot); |
| 2315 return rv; | 2340 return rv; |
| 2316 } | 2341 } |
| 2317 | 2342 |
| 2318 CK_OBJECT_HANDLE | 2343 CK_OBJECT_HANDLE |
| 2319 PK11_GetSymKeyHandle(PK11SymKey *symKey) | 2344 PK11_GetSymKeyHandle(PK11SymKey *symKey) |
| 2320 { | 2345 { |
| 2321 return symKey->objectID; | 2346 return symKey->objectID; |
| 2322 } | 2347 } |
| 2323 | 2348 |
| OLD | NEW |