Chromium Code Reviews| 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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 825 SECStatus |
| 826 PK11_EncryptWithSymKey(PK11SymKey *symKey, | 826 PK11_Decrypt(PK11SymKey *symKey, |
| 827 CK_MECHANISM_TYPE mechanism, SECItem *param, | 827 CK_MECHANISM_TYPE mechanism, SECItem *param, |
| 828 unsigned char *out, unsigned int *outLen, | 828 unsigned char *out, unsigned int *outLen, |
| 829 unsigned int maxLen, | 829 unsigned int maxLen, |
| 830 const unsigned char *data, unsigned dataLen) | 830 const unsigned char *enc, unsigned encLen) |
| 831 { | 831 { |
| 832 PK11SlotInfo *slot = symKey->slot; | 832 PK11SlotInfo *slot = symKey->slot; |
| 833 CK_MECHANISM mech = {0, NULL, 0 }; | 833 CK_MECHANISM mech = {0, NULL, 0 }; |
| 834 CK_ULONG len = maxLen; | 834 CK_ULONG len = maxLen; |
| 835 PRBool owner = PR_TRUE; | 835 PRBool owner = PR_TRUE; |
| 836 CK_SESSION_HANDLE session; | 836 CK_SESSION_HANDLE session; |
| 837 PRBool haslock = PR_FALSE; | 837 PRBool haslock = PR_FALSE; |
| 838 CK_RV crv; | 838 CK_RV crv; |
| 839 | 839 |
| 840 mech.mechanism = mechanism; | 840 mech.mechanism = mechanism; |
| 841 if (param) { | 841 if (param) { |
| 842 mech.pParameter = param->data; | 842 mech.pParameter = param->data; |
| 843 mech.ulParameterLen = param->len; | 843 mech.ulParameterLen = param->len; |
| 844 } | 844 } |
| 845 | 845 |
| 846 session = pk11_GetNewSession(slot, &owner); | 846 session = pk11_GetNewSession(slot, &owner); |
| 847 haslock = (!owner || !slot->isThreadSafe); | 847 haslock = (!owner || !slot->isThreadSafe); |
| 848 if (haslock) PK11_EnterSlotMonitor(slot); | 848 if (haslock) PK11_EnterSlotMonitor(slot); |
| 849 crv = PK11_GETTAB(slot)->C_EncryptInit(session, &mech, symKey->objectID); | 849 crv = PK11_GETTAB(slot)->C_DecryptInit(session, &mech, symKey->objectID); |
| 850 if (crv != CKR_OK) { | 850 if (crv != CKR_OK) { |
| 851 if (haslock) PK11_ExitSlotMonitor(slot); | 851 if (haslock) PK11_ExitSlotMonitor(slot); |
| 852 » pk11_CloseSession(slot,session,owner); | 852 » pk11_CloseSession(slot, session, owner); |
| 853 PORT_SetError( PK11_MapError(crv) ); | 853 PORT_SetError( PK11_MapError(crv) ); |
| 854 return SECFailure; | 854 return SECFailure; |
| 855 } | 855 } |
| 856 crv = PK11_GETTAB(slot)->C_Encrypt(session, (unsigned char *)data, | 856 |
| 857 dataLen, out, &len); | 857 crv = PK11_GETTAB(slot)->C_Decrypt(session, (unsigned char *)enc, encLen, |
| 858 out, &len); | |
| 858 if (haslock) PK11_ExitSlotMonitor(slot); | 859 if (haslock) PK11_ExitSlotMonitor(slot); |
| 859 pk11_CloseSession(slot,session,owner); | 860 pk11_CloseSession(slot, session, owner); |
| 860 *outLen = len; | 861 *outLen = len; |
| 861 if (crv != CKR_OK) { | 862 if (crv != CKR_OK) { |
| 862 PORT_SetError( PK11_MapError(crv) ); | 863 PORT_SetError( PK11_MapError(crv) ); |
| 863 return SECFailure; | 864 return SECFailure; |
| 864 } | 865 } |
| 865 return SECSuccess; | 866 return SECSuccess; |
| 866 } | 867 } |
| 867 | 868 |
| 868 SECStatus | 869 SECStatus |
| 869 PK11_DecryptWithSymKey(PK11SymKey *symKey, | 870 PK11_Encrypt(PK11SymKey *symKey, |
| 870 CK_MECHANISM_TYPE mechanism, SECItem *param, | 871 CK_MECHANISM_TYPE mechanism, SECItem *param, |
| 871 unsigned char *out, unsigned int *outLen, | 872 unsigned char *out, unsigned int *outLen, |
| 872 unsigned int maxLen, | 873 unsigned int maxLen, |
| 873 const unsigned char *enc, unsigned encLen) | 874 const unsigned char *data, unsigned int dataLen) |
| 874 { | 875 { |
| 875 PK11SlotInfo *slot = symKey->slot; | 876 PK11SlotInfo *slot = symKey->slot; |
| 876 CK_MECHANISM mech = {0, NULL, 0 }; | 877 CK_MECHANISM mech = {0, NULL, 0 }; |
| 877 CK_ULONG len = maxLen; | 878 CK_ULONG len = maxLen; |
| 878 PRBool owner = PR_TRUE; | 879 PRBool owner = PR_TRUE; |
| 879 CK_SESSION_HANDLE session; | 880 CK_SESSION_HANDLE session; |
| 880 PRBool haslock = PR_FALSE; | 881 PRBool haslock = PR_FALSE; |
| 881 CK_RV crv; | 882 CK_RV crv; |
| 882 | 883 |
| 883 mech.mechanism = mechanism; | 884 mech.mechanism = mechanism; |
| 884 if (param) { | 885 if (param) { |
| 885 mech.pParameter = param->data; | 886 mech.pParameter = param->data; |
| 886 mech.ulParameterLen = param->len; | 887 mech.ulParameterLen = param->len; |
| 887 } | 888 } |
| 888 | 889 |
| 889 session = pk11_GetNewSession(slot, &owner); | 890 session = pk11_GetNewSession(slot, &owner); |
| 890 haslock = (!owner || !slot->isThreadSafe); | 891 haslock = (!owner || !slot->isThreadSafe); |
| 891 if (haslock) PK11_EnterSlotMonitor(slot); | 892 if (haslock) PK11_EnterSlotMonitor(slot); |
| 892 crv = PK11_GETTAB(slot)->C_DecryptInit(session, &mech, symKey->objectID); | 893 crv = PK11_GETTAB(slot)->C_EncryptInit(session, &mech, symKey->objectID); |
| 893 if (crv != CKR_OK) { | 894 if (crv != CKR_OK) { |
| 894 if (haslock) PK11_ExitSlotMonitor(slot); | 895 if (haslock) PK11_ExitSlotMonitor(slot); |
| 895 » pk11_CloseSession(slot, session, owner); | 896 » pk11_CloseSession(slot,session,owner); |
| 896 PORT_SetError( PK11_MapError(crv) ); | 897 PORT_SetError( PK11_MapError(crv) ); |
| 897 return SECFailure; | 898 return SECFailure; |
| 898 } | 899 } |
| 899 | 900 crv = PK11_GETTAB(slot)->C_Encrypt(session, (unsigned char *)data, |
| 900 crv = PK11_GETTAB(slot)->C_Decrypt(session, (unsigned char *)enc, encLen, | 901 dataLen, out, &len); |
| 901 out, &len); | |
| 902 if (haslock) PK11_ExitSlotMonitor(slot); | 902 if (haslock) PK11_ExitSlotMonitor(slot); |
| 903 pk11_CloseSession(slot, session, owner); | 903 pk11_CloseSession(slot,session,owner); |
| 904 *outLen = len; | 904 *outLen = len; |
|
ramant (doing other things)
2013/03/29 19:35:10
nit: why delete spaces between arguments in line#
wtc
2013/03/29 20:52:19
What I did here was to reorder the PK11_Encrypt an
| |
| 905 if (crv != CKR_OK) { | 905 if (crv != CKR_OK) { |
| 906 PORT_SetError( PK11_MapError(crv) ); | 906 PORT_SetError( PK11_MapError(crv) ); |
| 907 return SECFailure; | 907 return SECFailure; |
| 908 } | 908 } |
| 909 return SECSuccess; | 909 return SECSuccess; |
| 910 } | 910 } |
| 911 | 911 |
| 912 /* | 912 /* |
| 913 * 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 |
| 914 * 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 |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1967 PORT_SetError( PK11_MapError(crv) ); | 1967 PORT_SetError( PK11_MapError(crv) ); |
| 1968 return NULL; | 1968 return NULL; |
| 1969 } | 1969 } |
| 1970 | 1970 |
| 1971 item->data = (unsigned char*) theTemplate[0].pValue; | 1971 item->data = (unsigned char*) theTemplate[0].pValue; |
| 1972 item->len =theTemplate[0].ulValueLen; | 1972 item->len =theTemplate[0].ulValueLen; |
| 1973 | 1973 |
| 1974 return item; | 1974 return item; |
| 1975 } | 1975 } |
| 1976 | 1976 |
| OLD | NEW |