/* * alg2268.c - implementation of the algorithm in RFC 2268 * * 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/. */
/* Step 1. Compute all values to the right of the key. */
L2 = cx->B;
L = L2 + len;
tmpB = L[-1]; for (i = (sizeof cx->B) - len; i > 0; --i) {
*L++ = tmpB = S[(PRUint8)(tmpB + *L2++)];
}
/* step 2. Adjust left most byte of effective key. */
i = (sizeof cx->B) - efLen8;
L = cx->B + i;
*L = tmpB = S[*L]; /* mask is always 0xff */
/* step 3. Recompute all values to the left of effective key. */
L2 = --L + efLen8; while (L >= cx->B) {
*L-- = tmpB = S[tmpB ^ *L2--];
}
#if !defined(IS_LITTLE_ENDIAN) for (i = 63; i >= 0; --i) {
SWAPK(i); /* candidate for unrolling */
} #endif return SECSuccess;
}
/* ** Create a new RC2 context suitable for RC2 encryption/decryption. ** "key" raw key data ** "len" the number of bytes of key data ** "iv" is the CBC initialization vector (if mode is NSS_RC2_CBC) ** "mode" one of NSS_RC2 or NSS_RC2_CBC ** "effectiveKeyLen" in bytes, not bits. ** ** When mode is set to NSS_RC2_CBC the RC2 cipher is run in "cipher block ** chaining" mode.
*/
RC2Context *
RC2_CreateContext(constunsignedchar *key, unsignedint len, constunsignedchar *iv, int mode, unsigned efLen8)
{
RC2Context *cx = PORT_ZNew(RC2Context); if (cx) {
SECStatus rv = RC2_InitContext(cx, key, len, iv, mode, efLen8, 0); if (rv != SECSuccess) {
RC2_DestroyContext(cx, PR_TRUE);
cx = NULL;
}
} return cx;
}
/* ** Destroy an RC2 encryption/decryption context. ** "cx" the context ** "freeit" if PR_TRUE then free the object as well as its sub-objects
*/ void
RC2_DestroyContext(RC2Context *cx, PRBool freeit)
{ if (cx) {
memset(cx, 0, sizeof *cx); if (freeit) {
PORT_Free(cx);
}
}
}
/* ** Perform RC2 encryption. ** "cx" the context ** "output" the output buffer to store the encrypted data. ** "outputLen" how much data is stored in "output". Set by the routine ** after some data is stored in output. ** "maxOutputLen" the maximum amount of data that can ever be ** stored in "output" ** "input" the input data ** "inputLen" the amount of input data
*/
SECStatus
RC2_Encrypt(RC2Context *cx, unsignedchar *output, unsignedint *outputLen, unsignedint maxOutputLen, constunsignedchar *input, unsignedint inputLen)
{
SECStatus rv = SECSuccess; if (inputLen) { if (inputLen % RC2_BLOCK_SIZE) {
PORT_SetError(SEC_ERROR_INPUT_LEN); return SECFailure;
} if (maxOutputLen < inputLen) {
PORT_SetError(SEC_ERROR_OUTPUT_LEN); return SECFailure;
}
rv = (*cx->enc)(cx, output, input, inputLen);
} if (rv == SECSuccess) {
*outputLen = inputLen;
} return rv;
}
/* ** Perform RC2 decryption. ** "cx" the context ** "output" the output buffer to store the decrypted data. ** "outputLen" how much data is stored in "output". Set by the routine ** after some data is stored in output. ** "maxOutputLen" the maximum amount of data that can ever be ** stored in "output" ** "input" the input data ** "inputLen" the amount of input data
*/
SECStatus
RC2_Decrypt(RC2Context *cx, unsignedchar *output, unsignedint *outputLen, unsignedint maxOutputLen, constunsignedchar *input, unsignedint inputLen)
{
SECStatus rv = SECSuccess; if (inputLen) { if (inputLen % RC2_BLOCK_SIZE) {
PORT_SetError(SEC_ERROR_INPUT_LEN); return SECFailure;
} if (maxOutputLen < inputLen) {
PORT_SetError(SEC_ERROR_OUTPUT_LEN); return SECFailure;
}
rv = (*cx->dec)(cx, output, input, inputLen);
} if (rv == SECSuccess) {
*outputLen = inputLen;
} return rv;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-04)
¤
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.