| 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 /* | 5 /* |
| 6 * crypto.c | 6 * crypto.c |
| 7 * | 7 * |
| 8 * This file implements the NSSCKFWCryptoOperation type and methods. | 8 * This file implements the NSSCKFWCryptoOperation type and methods. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * -- module fronts -- | 28 * -- module fronts -- |
| 29 * nssCKFWCryptoOperation_GetFinalLength | 29 * nssCKFWCryptoOperation_GetFinalLength |
| 30 * nssCKFWCryptoOperation_GetOperationLength | 30 * nssCKFWCryptoOperation_GetOperationLength |
| 31 * nssCKFWCryptoOperation_Final | 31 * nssCKFWCryptoOperation_Final |
| 32 * nssCKFWCryptoOperation_Update | 32 * nssCKFWCryptoOperation_Update |
| 33 * nssCKFWCryptoOperation_DigestUpdate | 33 * nssCKFWCryptoOperation_DigestUpdate |
| 34 * nssCKFWCryptoOperation_UpdateFinal | 34 * nssCKFWCryptoOperation_UpdateFinal |
| 35 */ | 35 */ |
| 36 | 36 |
| 37 struct NSSCKFWCryptoOperationStr { | 37 struct NSSCKFWCryptoOperationStr { |
| 38 /* NSSArena *arena; */ | 38 /* NSSArena *arena; */ |
| 39 NSSCKMDCryptoOperation *mdOperation; | 39 NSSCKMDCryptoOperation *mdOperation; |
| 40 NSSCKMDSession *mdSession; | 40 NSSCKMDSession *mdSession; |
| 41 NSSCKFWSession *fwSession; | 41 NSSCKFWSession *fwSession; |
| 42 NSSCKMDToken *mdToken; | 42 NSSCKMDToken *mdToken; |
| 43 NSSCKFWToken *fwToken; | 43 NSSCKFWToken *fwToken; |
| 44 NSSCKMDInstance *mdInstance; | 44 NSSCKMDInstance *mdInstance; |
| 45 NSSCKFWInstance *fwInstance; | 45 NSSCKFWInstance *fwInstance; |
| 46 NSSCKFWCryptoOperationType type; | 46 NSSCKFWCryptoOperationType type; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 /* | 49 /* |
| 50 * nssCKFWCrytoOperation_Create | 50 * nssCKFWCrytoOperation_Create |
| 51 */ | 51 */ |
| 52 NSS_EXTERN NSSCKFWCryptoOperation * | 52 NSS_EXTERN NSSCKFWCryptoOperation * |
| 53 nssCKFWCryptoOperation_Create( | 53 nssCKFWCryptoOperation_Create( |
| 54 NSSCKMDCryptoOperation *mdOperation, | 54 NSSCKMDCryptoOperation *mdOperation, |
| 55 NSSCKMDSession *mdSession, | 55 NSSCKMDSession *mdSession, |
| 56 NSSCKFWSession *fwSession, | 56 NSSCKFWSession *fwSession, |
| 57 NSSCKMDToken *mdToken, | 57 NSSCKMDToken *mdToken, |
| 58 NSSCKFWToken *fwToken, | 58 NSSCKFWToken *fwToken, |
| 59 NSSCKMDInstance *mdInstance, | 59 NSSCKMDInstance *mdInstance, |
| 60 NSSCKFWInstance *fwInstance, | 60 NSSCKFWInstance *fwInstance, |
| 61 NSSCKFWCryptoOperationType type, | 61 NSSCKFWCryptoOperationType type, |
| 62 CK_RV *pError | 62 CK_RV *pError) |
| 63 ) | 63 { |
| 64 { | 64 NSSCKFWCryptoOperation *fwOperation; |
| 65 NSSCKFWCryptoOperation *fwOperation; | 65 fwOperation = nss_ZNEW(NULL, NSSCKFWCryptoOperation); |
| 66 fwOperation = nss_ZNEW(NULL, NSSCKFWCryptoOperation); | 66 if (!fwOperation) { |
| 67 if (!fwOperation) { | 67 *pError = CKR_HOST_MEMORY; |
| 68 *pError = CKR_HOST_MEMORY; | 68 return (NSSCKFWCryptoOperation *)NULL; |
| 69 return (NSSCKFWCryptoOperation *)NULL; | 69 } |
| 70 } | 70 fwOperation->mdOperation = mdOperation; |
| 71 fwOperation->mdOperation = mdOperation; | 71 fwOperation->mdSession = mdSession; |
| 72 fwOperation->mdSession = mdSession; | 72 fwOperation->fwSession = fwSession; |
| 73 fwOperation->fwSession = fwSession; | 73 fwOperation->mdToken = mdToken; |
| 74 fwOperation->mdToken = mdToken; | 74 fwOperation->fwToken = fwToken; |
| 75 fwOperation->fwToken = fwToken; | 75 fwOperation->mdInstance = mdInstance; |
| 76 fwOperation->mdInstance = mdInstance; | 76 fwOperation->fwInstance = fwInstance; |
| 77 fwOperation->fwInstance = fwInstance; | 77 fwOperation->type = type; |
| 78 fwOperation->type = type; | 78 return fwOperation; |
| 79 return fwOperation; | |
| 80 } | 79 } |
| 81 | 80 |
| 82 /* | 81 /* |
| 83 * nssCKFWCryptoOperation_Destroy | 82 * nssCKFWCryptoOperation_Destroy |
| 84 */ | 83 */ |
| 85 NSS_EXTERN void | 84 NSS_EXTERN void |
| 86 nssCKFWCryptoOperation_Destroy | 85 nssCKFWCryptoOperation_Destroy( |
| 87 ( | 86 NSSCKFWCryptoOperation *fwOperation) |
| 88 NSSCKFWCryptoOperation *fwOperation | 87 { |
| 89 ) | 88 if ((NSSCKMDCryptoOperation *)NULL != fwOperation->mdOperation) { |
| 90 { | 89 if (fwOperation->mdOperation->Destroy) { |
| 91 if ((NSSCKMDCryptoOperation *) NULL != fwOperation->mdOperation) { | 90 fwOperation->mdOperation->Destroy( |
| 92 if (fwOperation->mdOperation->Destroy) { | |
| 93 fwOperation->mdOperation->Destroy( | |
| 94 fwOperation->mdOperation, | |
| 95 fwOperation, | |
| 96 fwOperation->mdInstance, | |
| 97 fwOperation->fwInstance); | |
| 98 } | |
| 99 } | |
| 100 nss_ZFreeIf(fwOperation); | |
| 101 } | |
| 102 | |
| 103 /* | |
| 104 * nssCKFWCryptoOperation_GetMDCryptoOperation | |
| 105 */ | |
| 106 NSS_EXTERN NSSCKMDCryptoOperation * | |
| 107 nssCKFWCryptoOperation_GetMDCryptoOperation | |
| 108 ( | |
| 109 NSSCKFWCryptoOperation *fwOperation | |
| 110 ) | |
| 111 { | |
| 112 return fwOperation->mdOperation; | |
| 113 } | |
| 114 | |
| 115 /* | |
| 116 * nssCKFWCryptoOperation_GetType | |
| 117 */ | |
| 118 NSS_EXTERN NSSCKFWCryptoOperationType | |
| 119 nssCKFWCryptoOperation_GetType | |
| 120 ( | |
| 121 NSSCKFWCryptoOperation *fwOperation | |
| 122 ) | |
| 123 { | |
| 124 return fwOperation->type; | |
| 125 } | |
| 126 | |
| 127 /* | |
| 128 * nssCKFWCryptoOperation_GetFinalLength | |
| 129 */ | |
| 130 NSS_EXTERN CK_ULONG | |
| 131 nssCKFWCryptoOperation_GetFinalLength | |
| 132 ( | |
| 133 NSSCKFWCryptoOperation *fwOperation, | |
| 134 CK_RV *pError | |
| 135 ) | |
| 136 { | |
| 137 if (!fwOperation->mdOperation->GetFinalLength) { | |
| 138 *pError = CKR_FUNCTION_FAILED; | |
| 139 return 0; | |
| 140 } | |
| 141 return fwOperation->mdOperation->GetFinalLength( | |
| 142 fwOperation->mdOperation, | 91 fwOperation->mdOperation, |
| 143 fwOperation, | 92 fwOperation, |
| 144 fwOperation->mdSession, | |
| 145 fwOperation->fwSession, | |
| 146 fwOperation->mdToken, | |
| 147 fwOperation->fwToken, | |
| 148 fwOperation->mdInstance, | 93 fwOperation->mdInstance, |
| 149 fwOperation->fwInstance, | 94 fwOperation->fwInstance); |
| 150 pError); | 95 } |
| 96 } |
| 97 nss_ZFreeIf(fwOperation); |
| 98 } |
| 99 |
| 100 /* |
| 101 * nssCKFWCryptoOperation_GetMDCryptoOperation |
| 102 */ |
| 103 NSS_EXTERN NSSCKMDCryptoOperation * |
| 104 nssCKFWCryptoOperation_GetMDCryptoOperation( |
| 105 NSSCKFWCryptoOperation *fwOperation) |
| 106 { |
| 107 return fwOperation->mdOperation; |
| 108 } |
| 109 |
| 110 /* |
| 111 * nssCKFWCryptoOperation_GetType |
| 112 */ |
| 113 NSS_EXTERN NSSCKFWCryptoOperationType |
| 114 nssCKFWCryptoOperation_GetType( |
| 115 NSSCKFWCryptoOperation *fwOperation) |
| 116 { |
| 117 return fwOperation->type; |
| 118 } |
| 119 |
| 120 /* |
| 121 * nssCKFWCryptoOperation_GetFinalLength |
| 122 */ |
| 123 NSS_EXTERN CK_ULONG |
| 124 nssCKFWCryptoOperation_GetFinalLength( |
| 125 NSSCKFWCryptoOperation *fwOperation, |
| 126 CK_RV *pError) |
| 127 { |
| 128 if (!fwOperation->mdOperation->GetFinalLength) { |
| 129 *pError = CKR_FUNCTION_FAILED; |
| 130 return 0; |
| 131 } |
| 132 return fwOperation->mdOperation->GetFinalLength( |
| 133 fwOperation->mdOperation, |
| 134 fwOperation, |
| 135 fwOperation->mdSession, |
| 136 fwOperation->fwSession, |
| 137 fwOperation->mdToken, |
| 138 fwOperation->fwToken, |
| 139 fwOperation->mdInstance, |
| 140 fwOperation->fwInstance, |
| 141 pError); |
| 151 } | 142 } |
| 152 | 143 |
| 153 /* | 144 /* |
| 154 * nssCKFWCryptoOperation_GetOperationLength | 145 * nssCKFWCryptoOperation_GetOperationLength |
| 155 */ | 146 */ |
| 156 NSS_EXTERN CK_ULONG | 147 NSS_EXTERN CK_ULONG |
| 157 nssCKFWCryptoOperation_GetOperationLength | 148 nssCKFWCryptoOperation_GetOperationLength( |
| 158 ( | 149 NSSCKFWCryptoOperation *fwOperation, |
| 159 NSSCKFWCryptoOperation *fwOperation, | 150 NSSItem *inputBuffer, |
| 160 NSSItem *inputBuffer, | 151 CK_RV *pError) |
| 161 CK_RV *pError | 152 { |
| 162 ) | 153 if (!fwOperation->mdOperation->GetOperationLength) { |
| 163 { | 154 *pError = CKR_FUNCTION_FAILED; |
| 164 if (!fwOperation->mdOperation->GetOperationLength) { | 155 return 0; |
| 165 *pError = CKR_FUNCTION_FAILED; | 156 } |
| 166 return 0; | 157 return fwOperation->mdOperation->GetOperationLength( |
| 167 } | 158 fwOperation->mdOperation, |
| 168 return fwOperation->mdOperation->GetOperationLength( | 159 fwOperation, |
| 169 fwOperation->mdOperation, | 160 fwOperation->mdSession, |
| 170 fwOperation, | 161 fwOperation->fwSession, |
| 171 fwOperation->mdSession, | 162 fwOperation->mdToken, |
| 172 fwOperation->fwSession, | 163 fwOperation->fwToken, |
| 173 fwOperation->mdToken, | 164 fwOperation->mdInstance, |
| 174 fwOperation->fwToken, | 165 fwOperation->fwInstance, |
| 175 fwOperation->mdInstance, | 166 inputBuffer, |
| 176 fwOperation->fwInstance, | 167 pError); |
| 177 inputBuffer, | |
| 178 pError); | |
| 179 } | 168 } |
| 180 | 169 |
| 181 /* | 170 /* |
| 182 * nssCKFWCryptoOperation_Final | 171 * nssCKFWCryptoOperation_Final |
| 183 */ | 172 */ |
| 184 NSS_EXTERN CK_RV | 173 NSS_EXTERN CK_RV |
| 185 nssCKFWCryptoOperation_Final | 174 nssCKFWCryptoOperation_Final( |
| 186 ( | 175 NSSCKFWCryptoOperation *fwOperation, |
| 187 NSSCKFWCryptoOperation *fwOperation, | 176 NSSItem *outputBuffer) |
| 188 NSSItem *outputBuffer | 177 { |
| 189 ) | 178 if (!fwOperation->mdOperation->Final) { |
| 190 { | 179 return CKR_FUNCTION_FAILED; |
| 191 if (!fwOperation->mdOperation->Final) { | 180 } |
| 192 return CKR_FUNCTION_FAILED; | 181 return fwOperation->mdOperation->Final( |
| 193 } | 182 fwOperation->mdOperation, |
| 194 return fwOperation->mdOperation->Final( | 183 fwOperation, |
| 195 fwOperation->mdOperation, | 184 fwOperation->mdSession, |
| 196 fwOperation, | 185 fwOperation->fwSession, |
| 197 fwOperation->mdSession, | 186 fwOperation->mdToken, |
| 198 fwOperation->fwSession, | 187 fwOperation->fwToken, |
| 199 fwOperation->mdToken, | 188 fwOperation->mdInstance, |
| 200 fwOperation->fwToken, | 189 fwOperation->fwInstance, |
| 201 fwOperation->mdInstance, | 190 outputBuffer); |
| 202 fwOperation->fwInstance, | |
| 203 outputBuffer); | |
| 204 } | 191 } |
| 205 | 192 |
| 206 /* | 193 /* |
| 207 * nssCKFWCryptoOperation_Update | 194 * nssCKFWCryptoOperation_Update |
| 208 */ | 195 */ |
| 209 NSS_EXTERN CK_RV | 196 NSS_EXTERN CK_RV |
| 210 nssCKFWCryptoOperation_Update | 197 nssCKFWCryptoOperation_Update( |
| 211 ( | 198 NSSCKFWCryptoOperation *fwOperation, |
| 212 NSSCKFWCryptoOperation *fwOperation, | 199 NSSItem *inputBuffer, |
| 213 NSSItem *inputBuffer, | 200 NSSItem *outputBuffer) |
| 214 NSSItem *outputBuffer | 201 { |
| 215 ) | 202 if (!fwOperation->mdOperation->Update) { |
| 216 { | 203 return CKR_FUNCTION_FAILED; |
| 217 if (!fwOperation->mdOperation->Update) { | 204 } |
| 218 return CKR_FUNCTION_FAILED; | 205 return fwOperation->mdOperation->Update( |
| 219 } | 206 fwOperation->mdOperation, |
| 220 return fwOperation->mdOperation->Update( | 207 fwOperation, |
| 221 fwOperation->mdOperation, | 208 fwOperation->mdSession, |
| 222 fwOperation, | 209 fwOperation->fwSession, |
| 223 fwOperation->mdSession, | 210 fwOperation->mdToken, |
| 224 fwOperation->fwSession, | 211 fwOperation->fwToken, |
| 225 fwOperation->mdToken, | 212 fwOperation->mdInstance, |
| 226 fwOperation->fwToken, | 213 fwOperation->fwInstance, |
| 227 fwOperation->mdInstance, | 214 inputBuffer, |
| 228 fwOperation->fwInstance, | 215 outputBuffer); |
| 229 inputBuffer, | |
| 230 outputBuffer); | |
| 231 } | 216 } |
| 232 | 217 |
| 233 /* | 218 /* |
| 234 * nssCKFWCryptoOperation_DigestUpdate | 219 * nssCKFWCryptoOperation_DigestUpdate |
| 235 */ | 220 */ |
| 236 NSS_EXTERN CK_RV | 221 NSS_EXTERN CK_RV |
| 237 nssCKFWCryptoOperation_DigestUpdate | 222 nssCKFWCryptoOperation_DigestUpdate( |
| 238 ( | 223 NSSCKFWCryptoOperation *fwOperation, |
| 239 NSSCKFWCryptoOperation *fwOperation, | 224 NSSItem *inputBuffer) |
| 240 NSSItem *inputBuffer | 225 { |
| 241 ) | 226 if (!fwOperation->mdOperation->DigestUpdate) { |
| 242 { | 227 return CKR_FUNCTION_FAILED; |
| 243 if (!fwOperation->mdOperation->DigestUpdate) { | 228 } |
| 244 return CKR_FUNCTION_FAILED; | 229 return fwOperation->mdOperation->DigestUpdate( |
| 245 } | 230 fwOperation->mdOperation, |
| 246 return fwOperation->mdOperation->DigestUpdate( | 231 fwOperation, |
| 247 fwOperation->mdOperation, | 232 fwOperation->mdSession, |
| 248 fwOperation, | 233 fwOperation->fwSession, |
| 249 fwOperation->mdSession, | 234 fwOperation->mdToken, |
| 250 fwOperation->fwSession, | 235 fwOperation->fwToken, |
| 251 fwOperation->mdToken, | 236 fwOperation->mdInstance, |
| 252 fwOperation->fwToken, | 237 fwOperation->fwInstance, |
| 253 fwOperation->mdInstance, | 238 inputBuffer); |
| 254 fwOperation->fwInstance, | |
| 255 inputBuffer); | |
| 256 } | 239 } |
| 257 | 240 |
| 258 /* | 241 /* |
| 259 * nssCKFWCryptoOperation_DigestKey | 242 * nssCKFWCryptoOperation_DigestKey |
| 260 */ | 243 */ |
| 261 NSS_EXTERN CK_RV | 244 NSS_EXTERN CK_RV |
| 262 nssCKFWCryptoOperation_DigestKey | 245 nssCKFWCryptoOperation_DigestKey( |
| 263 ( | 246 NSSCKFWCryptoOperation *fwOperation, |
| 264 NSSCKFWCryptoOperation *fwOperation, | 247 NSSCKFWObject *fwObject /* Key */ |
| 265 NSSCKFWObject *fwObject /* Key */ | 248 ) |
| 266 ) | 249 { |
| 267 { | 250 NSSCKMDObject *mdObject; |
| 268 NSSCKMDObject *mdObject; | 251 |
| 269 | 252 if (!fwOperation->mdOperation->DigestKey) { |
| 270 if (!fwOperation->mdOperation->DigestKey) { | 253 return CKR_FUNCTION_FAILED; |
| 271 return CKR_FUNCTION_FAILED; | 254 } |
| 272 } | 255 mdObject = nssCKFWObject_GetMDObject(fwObject); |
| 273 mdObject = nssCKFWObject_GetMDObject(fwObject); | 256 return fwOperation->mdOperation->DigestKey( |
| 274 return fwOperation->mdOperation->DigestKey( | 257 fwOperation->mdOperation, |
| 275 fwOperation->mdOperation, | 258 fwOperation, |
| 276 fwOperation, | 259 fwOperation->mdToken, |
| 277 fwOperation->mdToken, | 260 fwOperation->fwToken, |
| 278 fwOperation->fwToken, | 261 fwOperation->mdInstance, |
| 279 fwOperation->mdInstance, | 262 fwOperation->fwInstance, |
| 280 fwOperation->fwInstance, | 263 mdObject, |
| 281 mdObject, | 264 fwObject); |
| 282 fwObject); | |
| 283 } | 265 } |
| 284 | 266 |
| 285 /* | 267 /* |
| 286 * nssCKFWCryptoOperation_UpdateFinal | 268 * nssCKFWCryptoOperation_UpdateFinal |
| 287 */ | 269 */ |
| 288 NSS_EXTERN CK_RV | 270 NSS_EXTERN CK_RV |
| 289 nssCKFWCryptoOperation_UpdateFinal | 271 nssCKFWCryptoOperation_UpdateFinal( |
| 290 ( | 272 NSSCKFWCryptoOperation *fwOperation, |
| 291 NSSCKFWCryptoOperation *fwOperation, | 273 NSSItem *inputBuffer, |
| 292 NSSItem *inputBuffer, | 274 NSSItem *outputBuffer) |
| 293 NSSItem *outputBuffer | 275 { |
| 294 ) | 276 if (!fwOperation->mdOperation->UpdateFinal) { |
| 295 { | 277 return CKR_FUNCTION_FAILED; |
| 296 if (!fwOperation->mdOperation->UpdateFinal) { | 278 } |
| 297 return CKR_FUNCTION_FAILED; | 279 return fwOperation->mdOperation->UpdateFinal( |
| 298 } | 280 fwOperation->mdOperation, |
| 299 return fwOperation->mdOperation->UpdateFinal( | 281 fwOperation, |
| 300 fwOperation->mdOperation, | 282 fwOperation->mdSession, |
| 301 fwOperation, | 283 fwOperation->fwSession, |
| 302 fwOperation->mdSession, | 284 fwOperation->mdToken, |
| 303 fwOperation->fwSession, | 285 fwOperation->fwToken, |
| 304 fwOperation->mdToken, | 286 fwOperation->mdInstance, |
| 305 fwOperation->fwToken, | 287 fwOperation->fwInstance, |
| 306 fwOperation->mdInstance, | 288 inputBuffer, |
| 307 fwOperation->fwInstance, | 289 outputBuffer); |
| 308 inputBuffer, | |
| 309 outputBuffer); | |
| 310 } | 290 } |
| 311 | 291 |
| 312 /* | 292 /* |
| 313 * nssCKFWCryptoOperation_UpdateCombo | 293 * nssCKFWCryptoOperation_UpdateCombo |
| 314 */ | 294 */ |
| 315 NSS_EXTERN CK_RV | 295 NSS_EXTERN CK_RV |
| 316 nssCKFWCryptoOperation_UpdateCombo | 296 nssCKFWCryptoOperation_UpdateCombo( |
| 317 ( | 297 NSSCKFWCryptoOperation *fwOperation, |
| 318 NSSCKFWCryptoOperation *fwOperation, | 298 NSSCKFWCryptoOperation *fwPeerOperation, |
| 319 NSSCKFWCryptoOperation *fwPeerOperation, | 299 NSSItem *inputBuffer, |
| 320 NSSItem *inputBuffer, | 300 NSSItem *outputBuffer) |
| 321 NSSItem *outputBuffer | 301 { |
| 322 ) | 302 if (!fwOperation->mdOperation->UpdateCombo) { |
| 323 { | 303 return CKR_FUNCTION_FAILED; |
| 324 if (!fwOperation->mdOperation->UpdateCombo) { | 304 } |
| 325 return CKR_FUNCTION_FAILED; | 305 return fwOperation->mdOperation->UpdateCombo( |
| 326 } | 306 fwOperation->mdOperation, |
| 327 return fwOperation->mdOperation->UpdateCombo( | 307 fwOperation, |
| 328 fwOperation->mdOperation, | 308 fwPeerOperation->mdOperation, |
| 329 fwOperation, | 309 fwPeerOperation, |
| 330 fwPeerOperation->mdOperation, | 310 fwOperation->mdSession, |
| 331 fwPeerOperation, | 311 fwOperation->fwSession, |
| 332 fwOperation->mdSession, | 312 fwOperation->mdToken, |
| 333 fwOperation->fwSession, | 313 fwOperation->fwToken, |
| 334 fwOperation->mdToken, | 314 fwOperation->mdInstance, |
| 335 fwOperation->fwToken, | 315 fwOperation->fwInstance, |
| 336 fwOperation->mdInstance, | 316 inputBuffer, |
| 337 fwOperation->fwInstance, | 317 outputBuffer); |
| 338 inputBuffer, | 318 } |
| 339 outputBuffer); | |
| 340 } | |
| OLD | NEW |