ahcbcpad.c revision 65c4736d9c0ebc6d9b1d991593b55566909da9cd
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an
1413616670fcb95b9ef236351502e4884ddca8bfTinderbox User unpublished work protected as such under copyright law. This work
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews contains proprietary, confidential, and trade secret information of
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence RSA Data Security, Inc. Use, disclosure or reproduction without the
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater express written authorization of RSA Data Security, Inc. is
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews/* Define this so that the type of the 'this' pointer in the
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews virtual functions will be correct for this derived class.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#define THIS_ENCRYPT_DECRYPT struct AHSecretCBCPad
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington/* Inherit the base class destructor, block size,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews and decrypt init and update routines.
25a66b4e41e2b0a2af4840749bac80ae78c678bfMark Andrews AHChooseEncryptDestructor, AHChooseEncryptGetBlockLen,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence AHSecretCBCPadEncryptInit, AHChooseEncryptDecryptInit,
21f1794606dce19928cf455029e173321f166380Mark Andrews AHSecretCBCPadEncryptUpdate, AHChooseEncryptDecryptUpdate,
973a19342597823f111fce6a8cd5adfd0e2e7c0dMark Andrews AHSecretCBCPadEncryptFinal, AHSecretCBCPadDecryptFinal
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid LawrenceAHSecretCBCPad *AHSecretCBCPadConstructor2 (handler, infoType, info)
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington if (handler == (AHSecretCBCPad *)NULL_PTR) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /* This constructor is being used to do a new */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if ((handler = (AHSecretCBCPad *)T_malloc (sizeof (*handler)))
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /* Construct base class with the infoType and info. */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson (&handler->chooseEncryptDecrypt, infoType, info);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson handler->chooseEncryptDecrypt.encryptDecrypt.vTable = &V_TABLE;
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsint AHSecretCBCPadEncryptInit (handler, key, chooser, surrenderContext)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews /* For encryption, we need to track the input length */
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceunsigned char *partOut;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceunsigned char *partIn;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence /* For encryption, we need to track the input length */
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews handler->_inputRemainder = (handler->_inputRemainder + partInLen) % 8;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceunsigned char *partOut;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews T_memset ((POINTER)finalBuffer, padLen, padLen);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews /* Add the pad bytes. This should force the output of the final block.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson (handler, partOut, partOutLen, maxPartOutLen, finalBuffer, padLen,
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson randomAlgorithm, surrenderContext)) != 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein /* The encrypt final operation should have no output. */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein (handler, (unsigned char *)NULL_PTR, &dummyPartOutLen, 0,
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater (B_Algorithm *)NULL_PTR, (A_SURRENDER_CTX *)NULL_PTR)) != 0)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /* Restart the context. */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /* No need to zeroize the finalBuffer since it only contains pad bytes. */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm,
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontunsigned char *partOut;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence /* For now, the DecrypyFinal operations is set to output 16 bytes.
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington (handler, finalBuffer, &localPartOutLen, sizeof (finalBuffer),
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /* Check that padding is one 1 to eight 8's.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if ((padLen = (unsigned int)padBuffer[7]) == 0 || padLen > 8)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if ((*partOutLen = localPartOutLen - padLen) > maxPartOutLen)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ((POINTER)partOut, (POINTER)finalBuffer, *partOutLen);