2 * Copyright (c) 2000-2001,2011,2014 Apple 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/cssmtype.h>
28 #include <security_utilities/debugging.h>
30 #define cspSigDebug(args...) secdebug("cspSig", ## args)
32 SignatureContext::~SignatureContext()
39 /* both sign & verify */
40 void SignatureContext::init(
41 const Context
&context
,
45 mSigner
.signerInit(context
, isSigning
);
49 /* both sign & verify */
50 void SignatureContext::update(
53 mDigest
.digestUpdate(data
.Data
, data
.Length
);
57 void SignatureContext::final(
62 void *sig
= out
.data();
63 size_t sigLen
= out
.length();
65 /* first obtain the digest */
66 digestLen
= mDigest
.digestSizeInBytes();
67 digest
= session().malloc(digestLen
);
68 mDigest
.digestFinal(digest
);
78 session().free(digest
);
81 session().free(digest
);
82 if(out
.length() < sigLen
) {
83 cspSigDebug("SignatureContext: mallocd sig too small!");
84 CssmError::throwMe(CSSMERR_CSP_INTERNAL_ERROR
);
90 void SignatureContext::final(
96 /* first obtain the digest */
97 digestLen
= mDigest
.digestSizeInBytes();
98 digest
= session().malloc(digestLen
);
99 mDigest
.digestFinal(digest
);
103 mSigner
.verify(digest
,
109 session().free(digest
);
112 session().free(digest
);
115 size_t SignatureContext::outputSize(
119 return mSigner
.maxSigSize();
122 /* for raw sign/verify - optionally called after init */
123 void SignatureContext::setDigestAlgorithm(
124 CSSM_ALGORITHMS digestAlg
)
126 mSigner
.setDigestAlg(digestAlg
);