2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * SignatureContext.h - AppleCSPContext sublass for generic sign/verify
23 #include "SignatureContext.h"
24 #include "AppleCSPUtils.h"
25 #include "AppleCSPSession.h"
26 #include <Security/utilities.h>
27 #include <Security/cssmtype.h>
29 #include <Security/debugging.h>
31 #define cspSigDebug(args...) secdebug("cspSig", ## args)
33 SignatureContext::~SignatureContext()
40 /* both sign & verify */
41 void SignatureContext::init(
42 const Context
&context
,
46 mSigner
.signerInit(context
, isSigning
);
50 /* both sign & verify */
51 void SignatureContext::update(
54 mDigest
.digestUpdate(data
.Data
, data
.Length
);
58 void SignatureContext::final(
63 void *sig
= out
.data();
64 size_t sigLen
= out
.length();
66 /* first obtain the digest */
67 digestLen
= mDigest
.digestSizeInBytes();
68 digest
= session().malloc(digestLen
);
69 mDigest
.digestFinal(digest
);
79 session().free(digest
);
82 session().free(digest
);
83 if(out
.length() < sigLen
) {
84 cspSigDebug("SignatureContext: mallocd sig too small!");
85 CssmError::throwMe(CSSMERR_CSP_INTERNAL_ERROR
);
91 void SignatureContext::final(
97 /* first obtain the digest */
98 digestLen
= mDigest
.digestSizeInBytes();
99 digest
= session().malloc(digestLen
);
100 mDigest
.digestFinal(digest
);
104 mSigner
.verify(digest
,
110 session().free(digest
);
113 session().free(digest
);
116 size_t SignatureContext::outputSize(
120 return mSigner
.maxSigSize();
123 /* for raw sign/verify - optionally called after init */
124 void SignatureContext::setDigestAlgorithm(
125 CSSM_ALGORITHMS digestAlg
)
127 mSigner
.setDigestAlg(digestAlg
);