3 * Implements both normal and PGP-specific CFB mode.
5 * Copyright (c) 2005 Marko Kreen
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * contrib/pgcrypto/pgp-cfb.c
53 int resync,
uint8 *iv)
91 * Data processing for normal CFB. (PGP_PKT_SYMENCRYPTED_DATA_MDC)
98 for (
i = ctx->
pos; i < ctx->pos +
len;
i++)
109 for (
i = ctx->
pos; i < ctx->pos +
len;
i++)
119 * Data processing for old PGP CFB mode. (PGP_PKT_SYMENCRYPTED_DATA)
121 * The goal is to hide the horror from the rest of the code,
122 * thus its all concentrated here.
130 /* block #2 is 2 bytes long */
136 for (
i = ctx->
pos; i < ctx->pos + n;
i++)
150 for (
i = ctx->
pos; i < ctx->pos +
len;
i++)
162 /* block #2 is 2 bytes long */
168 for (
i = ctx->
pos; i < ctx->pos + n;
i++)
184 for (
i = ctx->
pos; i < ctx->pos +
len;
i++)
194 * common code for both encrypt and decrypt.
203 while (
len > 0 && ctx->
pos > 0)
209 n = mix_data(ctx,
data, n, dst);
233 res = mix_data(ctx,
data, n, dst);
void pfree(void *pointer)
void * palloc0(Size size)
static int mix_decrypt_resync(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
int pgp_cfb_encrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
void pgp_cfb_free(PGP_CFB *ctx)
static int mix_encrypt_resync(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
static int cfb_process(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst, mix_data_t mix_data)
int(* mix_data_t)(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
int pgp_cfb_decrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
static int mix_decrypt_normal(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
static int mix_encrypt_normal(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
int pgp_cfb_create(PGP_CFB **ctx_p, int algo, const uint8 *key, int key_len, int resync, uint8 *iv)
int pgp_load_cipher(int code, PX_Cipher **res)
void px_memset(void *ptr, int c, size_t len)
#define px_cipher_free(c)
#define px_cipher_block_size(c)
#define px_cipher_encrypt(c, padding, data, dlen, res, rlen)
#define px_cipher_init(c, k, klen, iv)
uint8 encbuf[PGP_MAX_BLOCK]