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