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 manages object type indepentent functions. | 5 * This file manages object type indepentent functions. |
6 */ | 6 */ |
7 #include "seccomon.h" | 7 #include "seccomon.h" |
8 #include "secmod.h" | 8 #include "secmod.h" |
9 #include "secmodi.h" | 9 #include "secmodi.h" |
10 #include "secmodti.h" | 10 #include "secmodti.h" |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 if (haslock) PK11_ExitSlotMonitor(slot); | 815 if (haslock) PK11_ExitSlotMonitor(slot); |
816 pk11_CloseSession(slot,session,owner); | 816 pk11_CloseSession(slot,session,owner); |
817 sig->len = len; | 817 sig->len = len; |
818 if (crv != CKR_OK) { | 818 if (crv != CKR_OK) { |
819 PORT_SetError( PK11_MapError(crv) ); | 819 PORT_SetError( PK11_MapError(crv) ); |
820 return SECFailure; | 820 return SECFailure; |
821 } | 821 } |
822 return SECSuccess; | 822 return SECSuccess; |
823 } | 823 } |
824 | 824 |
825 SECStatus | |
826 PK11_EncryptWithSymKey(PK11SymKey *symKey, | |
wtc
2013/03/26 18:24:46
The two new functions are very similar to the PK11
Ryan Sleevi
2013/03/26 18:39:14
I don't have strong feelings about this, although
| |
827 CK_MECHANISM_TYPE mechanism, SECItem *param, | |
828 unsigned char *out, unsigned int *outLen, | |
829 unsigned int maxLen, | |
830 const unsigned char *data, unsigned dataLen) | |
831 { | |
832 PK11SlotInfo *slot = symKey->slot; | |
833 CK_MECHANISM mech = {0, NULL, 0 }; | |
834 CK_ULONG len = maxLen; | |
835 PRBool owner = PR_TRUE; | |
836 CK_SESSION_HANDLE session; | |
837 PRBool haslock = PR_FALSE; | |
838 CK_RV crv; | |
839 | |
840 mech.mechanism = mechanism; | |
841 if (param) { | |
842 mech.pParameter = param->data; | |
843 mech.ulParameterLen = param->len; | |
844 } | |
845 | |
846 session = pk11_GetNewSession(slot, &owner); | |
847 haslock = (!owner || !slot->isThreadSafe); | |
848 if (haslock) PK11_EnterSlotMonitor(slot); | |
849 crv = PK11_GETTAB(slot)->C_EncryptInit(session, &mech, symKey->objectID); | |
850 if (crv != CKR_OK) { | |
851 if (haslock) PK11_ExitSlotMonitor(slot); | |
852 pk11_CloseSession(slot,session,owner); | |
853 PORT_SetError( PK11_MapError(crv) ); | |
854 return SECFailure; | |
855 } | |
856 crv = PK11_GETTAB(slot)->C_Encrypt(session, (unsigned char *)data, | |
857 dataLen, out, &len); | |
858 if (haslock) PK11_ExitSlotMonitor(slot); | |
859 pk11_CloseSession(slot,session,owner); | |
860 *outLen = len; | |
861 if (crv != CKR_OK) { | |
862 PORT_SetError( PK11_MapError(crv) ); | |
863 return SECFailure; | |
864 } | |
865 return SECSuccess; | |
866 } | |
867 | |
868 SECStatus | |
869 PK11_DecryptWithSymKey(PK11SymKey *symKey, | |
870 CK_MECHANISM_TYPE mechanism, SECItem *param, | |
871 unsigned char *out, unsigned int *outLen, | |
872 unsigned int maxLen, | |
873 const unsigned char *enc, unsigned encLen) | |
874 { | |
875 PK11SlotInfo *slot = symKey->slot; | |
876 CK_MECHANISM mech = {0, NULL, 0 }; | |
877 CK_ULONG len = maxLen; | |
878 PRBool owner = PR_TRUE; | |
879 CK_SESSION_HANDLE session; | |
880 PRBool haslock = PR_FALSE; | |
881 CK_RV crv; | |
882 | |
883 mech.mechanism = mechanism; | |
884 if (param) { | |
885 mech.pParameter = param->data; | |
886 mech.ulParameterLen = param->len; | |
887 } | |
888 | |
889 session = pk11_GetNewSession(slot, &owner); | |
890 haslock = (!owner || !slot->isThreadSafe); | |
891 if (haslock) PK11_EnterSlotMonitor(slot); | |
892 crv = PK11_GETTAB(slot)->C_DecryptInit(session, &mech, symKey->objectID); | |
893 if (crv != CKR_OK) { | |
894 if (haslock) PK11_ExitSlotMonitor(slot); | |
895 pk11_CloseSession(slot, session, owner); | |
896 PORT_SetError( PK11_MapError(crv) ); | |
897 return SECFailure; | |
898 } | |
899 | |
900 crv = PK11_GETTAB(slot)->C_Decrypt(session, (unsigned char *)enc, encLen, | |
901 out, &len); | |
902 if (haslock) PK11_ExitSlotMonitor(slot); | |
903 pk11_CloseSession(slot, session, owner); | |
904 *outLen = len; | |
905 if (crv != CKR_OK) { | |
906 PORT_SetError( PK11_MapError(crv) ); | |
907 return SECFailure; | |
908 } | |
909 return SECSuccess; | |
910 } | |
911 | |
825 /* | 912 /* |
826 * Now SSL 2.0 uses raw RSA stuff. These next to functions *must* use | 913 * Now SSL 2.0 uses raw RSA stuff. These next to functions *must* use |
827 * RSA keys, or they'll fail. We do the checks up front. If anyone comes | 914 * RSA keys, or they'll fail. We do the checks up front. If anyone comes |
828 * up with a meaning for rawdecrypt for any other public key operation, | 915 * up with a meaning for rawdecrypt for any other public key operation, |
829 * then we need to move this check into some of PK11_PubDecrypt callers, | 916 * then we need to move this check into some of PK11_PubDecrypt callers, |
830 * (namely SSL 2.0). | 917 * (namely SSL 2.0). |
831 */ | 918 */ |
832 static SECStatus | 919 static SECStatus |
833 pk11_PrivDecryptRaw(SECKEYPrivateKey *key, unsigned char *data, | 920 pk11_PrivDecryptRaw(SECKEYPrivateKey *key, unsigned char *data, |
834 unsigned *outLen, unsigned int maxLen, unsigned char *enc, | 921 unsigned *outLen, unsigned int maxLen, unsigned char *enc, |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1880 PORT_SetError( PK11_MapError(crv) ); | 1967 PORT_SetError( PK11_MapError(crv) ); |
1881 return NULL; | 1968 return NULL; |
1882 } | 1969 } |
1883 | 1970 |
1884 item->data = (unsigned char*) theTemplate[0].pValue; | 1971 item->data = (unsigned char*) theTemplate[0].pValue; |
1885 item->len =theTemplate[0].ulValueLen; | 1972 item->len =theTemplate[0].ulValueLen; |
1886 | 1973 |
1887 return item; | 1974 return item; |
1888 } | 1975 } |
1889 | 1976 |
OLD | NEW |