OLD | NEW |
| (Empty) |
1 Index: mozilla/security/nss/lib/pk11wrap/pk11obj.c | |
2 =================================================================== | |
3 --- mozilla/security/nss/lib/pk11wrap/pk11obj.c (revision 190722) | |
4 +++ mozilla/security/nss/lib/pk11wrap/pk11obj.c (working copy) | |
5 @@ -822,6 +822,93 @@ | |
6 return SECSuccess; | |
7 } | |
8 | |
9 +SECStatus | |
10 +PK11_Decrypt(PK11SymKey *symKey, | |
11 + CK_MECHANISM_TYPE mechanism, SECItem *param, | |
12 + unsigned char *out, unsigned int *outLen, | |
13 + unsigned int maxLen, | |
14 + const unsigned char *enc, unsigned encLen) | |
15 +{ | |
16 + PK11SlotInfo *slot = symKey->slot; | |
17 + CK_MECHANISM mech = {0, NULL, 0 }; | |
18 + CK_ULONG len = maxLen; | |
19 + PRBool owner = PR_TRUE; | |
20 + CK_SESSION_HANDLE session; | |
21 + PRBool haslock = PR_FALSE; | |
22 + CK_RV crv; | |
23 + | |
24 + mech.mechanism = mechanism; | |
25 + if (param) { | |
26 + mech.pParameter = param->data; | |
27 + mech.ulParameterLen = param->len; | |
28 + } | |
29 + | |
30 + session = pk11_GetNewSession(slot, &owner); | |
31 + haslock = (!owner || !slot->isThreadSafe); | |
32 + if (haslock) PK11_EnterSlotMonitor(slot); | |
33 + crv = PK11_GETTAB(slot)->C_DecryptInit(session, &mech, symKey->objectID); | |
34 + if (crv != CKR_OK) { | |
35 + if (haslock) PK11_ExitSlotMonitor(slot); | |
36 + pk11_CloseSession(slot, session, owner); | |
37 + PORT_SetError( PK11_MapError(crv) ); | |
38 + return SECFailure; | |
39 + } | |
40 + | |
41 + crv = PK11_GETTAB(slot)->C_Decrypt(session, (unsigned char *)enc, encLen, | |
42 + out, &len); | |
43 + if (haslock) PK11_ExitSlotMonitor(slot); | |
44 + pk11_CloseSession(slot, session, owner); | |
45 + *outLen = len; | |
46 + if (crv != CKR_OK) { | |
47 + PORT_SetError( PK11_MapError(crv) ); | |
48 + return SECFailure; | |
49 + } | |
50 + return SECSuccess; | |
51 +} | |
52 + | |
53 +SECStatus | |
54 +PK11_Encrypt(PK11SymKey *symKey, | |
55 + CK_MECHANISM_TYPE mechanism, SECItem *param, | |
56 + unsigned char *out, unsigned int *outLen, | |
57 + unsigned int maxLen, | |
58 + const unsigned char *data, unsigned int dataLen) | |
59 +{ | |
60 + PK11SlotInfo *slot = symKey->slot; | |
61 + CK_MECHANISM mech = {0, NULL, 0 }; | |
62 + CK_ULONG len = maxLen; | |
63 + PRBool owner = PR_TRUE; | |
64 + CK_SESSION_HANDLE session; | |
65 + PRBool haslock = PR_FALSE; | |
66 + CK_RV crv; | |
67 + | |
68 + mech.mechanism = mechanism; | |
69 + if (param) { | |
70 + mech.pParameter = param->data; | |
71 + mech.ulParameterLen = param->len; | |
72 + } | |
73 + | |
74 + session = pk11_GetNewSession(slot, &owner); | |
75 + haslock = (!owner || !slot->isThreadSafe); | |
76 + if (haslock) PK11_EnterSlotMonitor(slot); | |
77 + crv = PK11_GETTAB(slot)->C_EncryptInit(session, &mech, symKey->objectID); | |
78 + if (crv != CKR_OK) { | |
79 + if (haslock) PK11_ExitSlotMonitor(slot); | |
80 + pk11_CloseSession(slot,session,owner); | |
81 + PORT_SetError( PK11_MapError(crv) ); | |
82 + return SECFailure; | |
83 + } | |
84 + crv = PK11_GETTAB(slot)->C_Encrypt(session, (unsigned char *)data, | |
85 + dataLen, out, &len); | |
86 + if (haslock) PK11_ExitSlotMonitor(slot); | |
87 + pk11_CloseSession(slot,session,owner); | |
88 + *outLen = len; | |
89 + if (crv != CKR_OK) { | |
90 + PORT_SetError( PK11_MapError(crv) ); | |
91 + return SECFailure; | |
92 + } | |
93 + return SECSuccess; | |
94 +} | |
95 + | |
96 /* | |
97 * Now SSL 2.0 uses raw RSA stuff. These next to functions *must* use | |
98 * RSA keys, or they'll fail. We do the checks up front. If anyone comes | |
99 Index: mozilla/security/nss/lib/pk11wrap/pk11pub.h | |
100 =================================================================== | |
101 --- mozilla/security/nss/lib/pk11wrap/pk11pub.h (revision 190722) | |
102 +++ mozilla/security/nss/lib/pk11wrap/pk11pub.h (working copy) | |
103 @@ -266,7 +266,7 @@ | |
104 CK_MECHANISM_TYPE PK11_MapSignKeyType(KeyType keyType); | |
105 | |
106 /********************************************************************** | |
107 - * Symetric, Public, and Private Keys | |
108 + * Symmetric, Public, and Private Keys | |
109 **********************************************************************/ | |
110 void PK11_FreeSymKey(PK11SymKey *key); | |
111 PK11SymKey *PK11_ReferenceSymKey(PK11SymKey *symKey); | |
112 @@ -508,6 +508,17 @@ | |
113 void *wincx); | |
114 int PK11_GetPrivateModulusLen(SECKEYPrivateKey *key); | |
115 | |
116 +SECStatus PK11_Decrypt(PK11SymKey *symkey, | |
117 + CK_MECHANISM_TYPE mechanism, SECItem *param, | |
118 + unsigned char *out, unsigned int *outLen, | |
119 + unsigned int maxLen, | |
120 + const unsigned char *enc, unsigned int encLen); | |
121 +SECStatus PK11_Encrypt(PK11SymKey *symKey, | |
122 + CK_MECHANISM_TYPE mechanism, SECItem *param, | |
123 + unsigned char *out, unsigned int *outLen, | |
124 + unsigned int maxLen, | |
125 + const unsigned char *data, unsigned int dataLen); | |
126 + | |
127 /* note: despite the name, this function takes a private key. */ | |
128 SECStatus PK11_PubDecryptRaw(SECKEYPrivateKey *key, unsigned char *data, | |
129 unsigned *outLen, unsigned int maxLen, unsigned char *enc, unsigned encLen); | |
OLD | NEW |