tf_cbc_encrypt(key, ctr, srcblk, srcblk, lblock);
else if (ctr_mode == TFC_MODE_CBC && do_edcrypt == TFC_DO_DECRYPT)
tf_cbc_decrypt(key, ctr, srcblk, srcblk, lblock);
+ else if (ctr_mode == TFC_MODE_PCBC && do_edcrypt == TFC_DO_ENCRYPT)
+ tf_pcbc_encrypt(key, ctr, srcblk, srcblk, lblock);
+ else if (ctr_mode == TFC_MODE_PCBC && do_edcrypt == TFC_DO_DECRYPT)
+ tf_pcbc_decrypt(key, ctr, srcblk, srcblk, lblock);
delta_processed += lblock;
}
ctr_mode = TFC_MODE_STREAM;
else if (!strcasecmp(d, "cbc"))
ctr_mode = TFC_MODE_CBC;
+ else if (!strcasecmp(d, "pcbc"))
+ ctr_mode = TFC_MODE_PCBC;
else if (!strcasecmp(d, "ecb"))
ctr_mode = TFC_MODE_ECB;
else if (!strcasecmp(d, "xts"))
case TFC_MODE_XTS: return "XTS";
case TFC_MODE_ECB: return "ECB";
case TFC_MODE_CBC: return "CBC";
+ case TFC_MODE_PCBC: return "PCBC";
}
return NULL;
ctr_mode = TFC_MODE_STREAM;
else if (!strcasecmp(optarg, "cbc"))
ctr_mode = TFC_MODE_CBC;
+ else if (!strcasecmp(optarg, "pcbc"))
+ ctr_mode = TFC_MODE_PCBC;
else if (!strcasecmp(optarg, "ecb"))
ctr_mode = TFC_MODE_ECB;
else if (!strcasecmp(optarg, "xts"))
tf_cbc_encrypt(key, ctr, dstblk, srcblk, ldone);
else if (ctr_mode == TFC_MODE_CBC && do_edcrypt == TFC_DO_DECRYPT)
tf_cbc_decrypt(key, ctr, dstblk, srcblk, ldone);
+ else if (ctr_mode == TFC_MODE_PCBC && do_edcrypt == TFC_DO_ENCRYPT)
+ tf_pcbc_encrypt(key, ctr, dstblk, srcblk, ldone);
+ else if (ctr_mode == TFC_MODE_PCBC && do_edcrypt == TFC_DO_DECRYPT)
+ tf_pcbc_decrypt(key, ctr, dstblk, srcblk, ldone);
else if (ctr_mode == TFC_MODE_PLAIN)
memcpy(dstblk, srcblk, ldone);
else if (ctr_mode == TFC_MODE_XTS) tf_xts_decrypt(key, xtskey, ctr, tmpdata, macvrfy, TF_FROM_BITS(macbits), xtsblocks);
else if (ctr_mode == TFC_MODE_ECB) tf_ecb_decrypt(key, tmpdata, macvrfy, TF_FROM_BITS(macbits));
else if (ctr_mode == TFC_MODE_CBC) tf_cbc_decrypt(key, ctr, tmpdata, macvrfy, TF_FROM_BITS(macbits));
+ else if (ctr_mode == TFC_MODE_PCBC) tf_pcbc_decrypt(key, ctr, tmpdata, macvrfy, TF_FROM_BITS(macbits));
if (!memcmp(tmpdata, macresult, TF_FROM_BITS(macbits))) {
if (quiet == NO) {
else if (ctr_mode == TFC_MODE_XTS) tf_xts_encrypt(key, xtskey, ctr, tmpdata, macresult, TF_FROM_BITS(macbits), xtsblocks);
else if (ctr_mode == TFC_MODE_ECB) tf_ecb_encrypt(key, tmpdata, macresult, TF_FROM_BITS(macbits));
else if (ctr_mode == TFC_MODE_CBC) tf_cbc_encrypt(key, ctr, tmpdata, macresult, TF_FROM_BITS(macbits));
+ else if (ctr_mode == TFC_MODE_PCBC) tf_pcbc_encrypt(key, ctr, tmpdata, macresult, TF_FROM_BITS(macbits));
memset(macresult, 0, sizeof(macresult));
if (!do_mac_file) {
enum { TFC_OUTFMT_HEX = 1, TFC_OUTFMT_B64, TFC_OUTFMT_RAW };
enum {
TFC_MODE_SKSUM = -2, TFC_MODE_PLAIN = -1, TFC_MODE_CTR = 1,
- TFC_MODE_STREAM, TFC_MODE_XTS, TFC_MODE_ECB, TFC_MODE_CBC
+ TFC_MODE_STREAM, TFC_MODE_XTS, TFC_MODE_ECB, TFC_MODE_CBC, TFC_MODE_PCBC
};
enum { TFC_CTR_SHOW = 1, TFC_CTR_HEAD, TFC_CTR_RAND, TFC_CTR_ZERO, TFC_CTR_SSET };
enum { TFC_NO_FTRUNC, TFC_DO_FTRUNC, TFC_FTRUNC_TAIL };
void tf_ecb_decrypt(const void *key, void *out, const void *in, size_t sz);
void tf_cbc_encrypt(const void *key, void *iv, void *out, const void *in, size_t sz);
void tf_cbc_decrypt(const void *key, void *iv, void *out, const void *in, size_t sz);
+void tf_pcbc_encrypt(const void *key, void *iv, void *out, const void *in, size_t sz);
+void tf_pcbc_decrypt(const void *key, void *iv, void *out, const void *in, size_t sz);
void tf_xts_encrypt(const void *keyx, const void *keyz, void *ctr, void *out, const void *in, size_t sz, size_t bpi);
void tf_xts_decrypt(const void *keyx, const void *keyz, void *ctr, void *out, const void *in, size_t sz, size_t bpi);
--- /dev/null
+#include <string.h>
+#include "tfdef.h"
+
+void tf_pcbc_encrypt(const void *key, void *iv, void *out, const void *in, size_t sz)
+{
+ const TF_BYTE_TYPE *uin = (const TF_BYTE_TYPE *)in;
+ TF_BYTE_TYPE *uout = (TF_BYTE_TYPE *)out;
+ TF_UNIT_TYPE x[TF_NR_BLOCK_UNITS], y[TF_NR_BLOCK_UNITS];
+ TF_UNIT_TYPE *uiv = (TF_UNIT_TYPE *)iv;
+ const TF_UNIT_TYPE *ukey = (const TF_UNIT_TYPE *)key;
+ size_t sl = sz, i;
+
+ if (sl >= TF_BLOCK_SIZE) {
+ do {
+ memcpy(x, uin, TF_BLOCK_SIZE);
+ uin += TF_BLOCK_SIZE;
+ data_to_words(x, TF_BLOCK_SIZE);
+
+ for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] = x[i] ^ uiv[i];
+ tf_encrypt_rawblk(y, y, ukey);
+ for (i = 0; i < TF_NR_BLOCK_UNITS; i++) uiv[i] = y[i] ^ x[i];
+
+ data_to_words(y, TF_BLOCK_SIZE);
+ memcpy(uout, y, TF_BLOCK_SIZE);
+ uout += TF_BLOCK_SIZE;
+ } while ((sl -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
+ }
+
+ if (sl) {
+ memset(x, 0, TF_BLOCK_SIZE);
+ memcpy(x, uin, sl);
+ data_to_words(x, TF_BLOCK_SIZE);
+
+ ctr_inc(uiv, TF_NR_BLOCK_UNITS);
+ tf_encrypt_rawblk(y, uiv, ukey);
+ for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
+
+ data_to_words(y, TF_BLOCK_SIZE);
+ memcpy(uout, y, sl);
+ }
+
+ memset(x, 0, TF_BLOCK_SIZE);
+ memset(y, 0, TF_BLOCK_SIZE);
+}
+
+void tf_pcbc_decrypt(const void *key, void *iv, void *out, const void *in, size_t sz)
+{
+ const TF_BYTE_TYPE *uin = (const TF_BYTE_TYPE *)in;
+ TF_BYTE_TYPE *uout = (TF_BYTE_TYPE *)out;
+ TF_UNIT_TYPE x[TF_NR_BLOCK_UNITS], y[TF_NR_BLOCK_UNITS];
+ TF_UNIT_TYPE *uiv = (TF_UNIT_TYPE *)iv;
+ const TF_UNIT_TYPE *ukey = (const TF_UNIT_TYPE *)key;
+ size_t sl = sz, i;
+
+ if (sl >= TF_BLOCK_SIZE) {
+ do {
+ memcpy(x, uin, TF_BLOCK_SIZE);
+ uin += TF_BLOCK_SIZE;
+ data_to_words(x, TF_BLOCK_SIZE);
+
+ tf_decrypt_rawblk(y, x, ukey);
+ for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= uiv[i];
+ for (i = 0; i < TF_NR_BLOCK_UNITS; i++) uiv[i] = y[i] ^ x[i];
+
+ data_to_words(y, TF_BLOCK_SIZE);
+ memcpy(uout, y, TF_BLOCK_SIZE);
+ uout += TF_BLOCK_SIZE;
+ } while ((sl -= TF_BLOCK_SIZE) >= TF_BLOCK_SIZE);
+ }
+
+ if (sl) {
+ memset(x, 0, TF_BLOCK_SIZE);
+ memcpy(x, uin, sl);
+ data_to_words(x, TF_BLOCK_SIZE);
+
+ ctr_inc(uiv, TF_NR_BLOCK_UNITS);
+ tf_encrypt_rawblk(y, uiv, ukey);
+ for (i = 0; i < TF_NR_BLOCK_UNITS; i++) y[i] ^= x[i];
+
+ data_to_words(y, TF_BLOCK_SIZE);
+ memcpy(uout, y, sl);
+ }
+
+ memset(x, 0, TF_BLOCK_SIZE);
+ memset(y, 0, TF_BLOCK_SIZE);
+}