security/nss/lib/ckfw/crypto.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial