/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * SSL Primitives: Public HKDF and AEAD Functions * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
struct SSLAeadContextStr { /* sigh, the API creates a single context, but then uses either encrypt * and decrypt on that context. We should take an encrypt/decrypt
* variable here, but for now create two contexts. */
PK11Context *encryptContext;
PK11Context *decryptContext; int tagLen; int ivLen; unsignedchar iv[MAX_IV_LENGTH];
};
/* We really need to change the API to Create a context for each * encrypt and decrypt rather than a single call that does both. it's * almost certain that the underlying application tries to use the same
* context for both. */
out->encryptContext = PK11_CreateContextBySymKey(mech,
CKA_NSS_MESSAGE | CKA_ENCRYPT,
key, &nullParams); if (out->encryptContext == NULL) { goto loser;
}
/* Bug 1529440 exists to refactor this and the other AEAD uses. */ static SECStatus
ssl_AeadInner(const SSLAeadContext *ctx, PK11Context *context,
PRBool decrypt, PRUint64 counter, const PRUint8 *aad, unsignedint aadLen, const PRUint8 *in, unsignedint inLen,
PRUint8 *out, unsignedint *outLen, unsignedint maxOut)
{ if (ctx == NULL || (aad == NULL && aadLen > 0) || in == NULL ||
out == NULL || outLen == NULL) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
}
// Setup the nonce.
PRUint8 nonce[sizeof(counter)] = { 0 };
sslBuffer nonceBuf = SSL_BUFFER_FIXED(nonce, sizeof(counter));
SECStatus rv = sslBuffer_AppendNumber(&nonceBuf, counter, sizeof(counter)); if (rv != SECSuccess) {
PORT_Assert(0); return SECFailure;
} /* at least on encrypt, we should not be using CKG_NO_GENERATE, but * the current experimental API has the application tracking the counter * rather than token. We should look at the QUIC code and see if the * counter can be moved internally where it belongs. That would * also get rid of the formatting code above and have the API
* call tls13_AEAD directly in SSLExp_Aead* */ return tls13_AEAD(context, decrypt, CKG_NO_GENERATE, 0, ctx->iv, NULL,
ctx->ivLen, nonce, sizeof(counter), aad, aadLen,
out, outLen, maxOut, ctx->tagLen, in, inLen);
}
/* Internal output len/buf, for use if the caller allocated and requested * less than one block of output. |oneBlock| should have size equal to the
* largest block size supported below. */
PRUint8 oneBlock[AES_BLOCK_SIZE];
PRUint8 *outMask_ = outMask; unsignedint maskLen_ = maskLen;
switch (ctx->mech) { case CKM_AES_ECB: if (sampleLen < AES_BLOCK_SIZE) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
} if (maskLen_ < AES_BLOCK_SIZE) {
outMask_ = oneBlock;
maskLen_ = sizeof(oneBlock);
}
rv = PK11_Encrypt(ctx->secret,
ctx->mech,
NULL,
outMask_, &outMaskLen, maskLen_,
sample, AES_BLOCK_SIZE); if (rv == SECSuccess &&
maskLen < AES_BLOCK_SIZE) {
memcpy(outMask, outMask_, maskLen);
} break; case CKM_NSS_CHACHA20_CTR:
paramLen = 16; /* fall through */ case CKM_CHACHA20:
paramLen = (paramLen) ? paramLen : sizeof(CK_CHACHA20_PARAMS); if (sampleLen < paramLen) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.