Remove lib/fko.h dependency on rijndael.h

This commit is contained in:
Michael Rash
2013-02-28 21:47:43 -05:00
parent 22316b796c
commit ffcb77552b
9 changed files with 63 additions and 65 deletions
-21
View File
@@ -55,27 +55,6 @@ digest_strtoint(const char *dt_str)
return(-1);
}
/* Convert an encryption_mode string to its integer value.
*/
static int
enc_mode_strtoint(const char *enc_mode_str)
{
if(strcasecmp(enc_mode_str, "cbc") == 0)
return(FKO_ENC_MODE_CBC);
else if(strcasecmp(enc_mode_str, "ecb") == 0)
return(FKO_ENC_MODE_ECB);
else if(strcasecmp(enc_mode_str, "cfb") == 0)
return(FKO_ENC_MODE_CFB);
else if(strcasecmp(enc_mode_str, "pcbc") == 0)
return(-1); /* not supported yet */
else if(strcasecmp(enc_mode_str, "ofb") == 0)
return(FKO_ENC_MODE_OFB);
else if(strcasecmp(enc_mode_str, "ctr") == 0)
return(FKO_ENC_MODE_CTR);
else
return(-1);
}
/* Convert a protocol string to its integer value.
*/
static int
+10 -1
View File
@@ -867,7 +867,16 @@ get_keys(fko_ctx_t ctx, fko_cli_options_t *options,
{
*key_len = fko_base64_decode(options->key_base64,
(unsigned char *) options->key);
memcpy(key, options->key, RIJNDAEL_MAX_KEYSIZE);
if(*key_len > 0 && *key_len < MAX_KEY_LEN)
{
//memcpy(key, options->key, *key_len);
memcpy(key, options->key, 32);
}
else
{
printf("FIXME bad\n");
exit(EXIT_FAILURE);
}
}
else
{
+18 -6
View File
@@ -111,8 +111,7 @@ get_random_data(unsigned char *data, const size_t len)
/*** These are Rijndael-specific functions ***/
/* Rijndael function to generate initial salt and initialization vector
* (iv). This is is done to be compatible with the data produced via
* the Perl Crypt::CBC module's use of Rijndael.
* (iv). This is is done to be compatible with the data produced via OpenSSL
*/
static void
rij_salt_and_iv(RIJNDAEL_context *ctx, const char *key,
@@ -208,11 +207,24 @@ rijndael_init(RIJNDAEL_context *ctx, const char *key,
int encryption_mode)
{
/* The default (set in fko.h) is CBC mode
/* The default is Rijndael in CBC mode
*/
if(encryption_mode == FKO_ENC_MODE_CBC_LEGACY_IV)
ctx->mode = FKO_ENC_MODE_CBC;
else
if(encryption_mode == FKO_ENC_MODE_CBC
|| encryption_mode == FKO_ENC_MODE_CBC_LEGACY_IV)
ctx->mode = MODE_CBC;
else if(encryption_mode == FKO_ENC_MODE_CFB)
ctx->mode = MODE_CFB;
else if(encryption_mode == FKO_ENC_MODE_PCBC)
ctx->mode = MODE_PCBC;
else if(encryption_mode == FKO_ENC_MODE_OFB)
ctx->mode = MODE_OFB;
else if(encryption_mode == FKO_ENC_MODE_CTR)
ctx->mode = MODE_CTR;
else if(encryption_mode == FKO_ENC_MODE_CFB)
ctx->mode = MODE_CFB;
else if(encryption_mode == FKO_ENC_MODE_ECB)
ctx->mode = MODE_ECB;
else /* shouldn't get this far */
ctx->mode = encryption_mode;
/* Generate the salt and initialization vector.
+8 -9
View File
@@ -33,7 +33,6 @@
#include <time.h>
#include "rijndael.h" /* For encryption modes */
#include "digest.h"
#ifdef __cplusplus
@@ -107,16 +106,16 @@ typedef enum {
FKO_LAST_ENCRYPTION_TYPE /* Always leave this as the last one */
} fko_encryption_type_t;
/* Symmetric encryption modes derived from rijndael.h
/* Symmetric encryption modes to correspond to rijndael.h
*/
typedef enum {
FKO_ENC_MODE_UNKNOWN = 0,
FKO_ENC_MODE_ECB = MODE_ECB,
FKO_ENC_MODE_CBC = MODE_CBC,
FKO_ENC_MODE_CFB = MODE_CFB,
FKO_ENC_MODE_PCBC = MODE_PCBC,
FKO_ENC_MODE_OFB = MODE_OFB,
FKO_ENC_MODE_CTR = MODE_CTR,
FKO_ENC_MODE_ECB,
FKO_ENC_MODE_CBC,
FKO_ENC_MODE_CFB,
FKO_ENC_MODE_PCBC,
FKO_ENC_MODE_OFB,
FKO_ENC_MODE_CTR,
FKO_ENC_MODE_ASYMMETRIC, /* placeholder when GPG is used */
FKO_ENC_MODE_CBC_LEGACY_IV, /* for the old zero-padding strategy */
FKO_LAST_ENC_MODE /* Always leave this as the last one */
@@ -192,7 +191,7 @@ typedef enum {
#define FKO_DEFAULT_MSG_TYPE FKO_ACCESS_MSG
#define FKO_DEFAULT_DIGEST FKO_DIGEST_SHA256
#define FKO_DEFAULT_ENCRYPTION FKO_ENCRYPTION_RIJNDAEL
#define FKO_DEFAULT_ENC_MODE MODE_CBC
#define FKO_DEFAULT_ENC_MODE FKO_ENC_MODE_CBC
/* Define the consistent prefixes or salt on some encryption schemes.
*/
+2 -3
View File
@@ -448,16 +448,15 @@ fko_get_spa_encryption_mode(fko_ctx_t ctx, int *enc_mode)
/* Encrypt the encoded SPA data.
*/
int
fko_encrypt_spa_data(fko_ctx_t ctx, const char * const enc_key, const int enc_key_len)
fko_encrypt_spa_data(fko_ctx_t ctx, const char * const enc_key,
const int enc_key_len)
{
int res = 0;
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
{
return(FKO_ERROR_CTX_NOT_INITIALIZED);
}
/* If there is no encoded data or the SPA data has been modified,
* go ahead and re-encode here.
+1 -2
View File
@@ -135,8 +135,7 @@ fko_new(fko_ctx_t *r_ctx)
return res;
}
/* Default Encryption Mode (Rijndael in EBC mode for backwards
* compatibility - it recommended to change this to CBC mode)
/* Default is Rijndael in CBC mode
*/
ctx->initval = FKO_CTX_INITIALIZED;
res = fko_set_spa_encryption_mode(ctx, FKO_DEFAULT_ENC_MODE);
+23
View File
@@ -78,6 +78,29 @@ is_valid_digest_len(const int len)
return(1);
}
/* Convert an encryption_mode string to its integer value.
*/
int
enc_mode_strtoint(const char *enc_mode_str)
{
if(strcasecmp(enc_mode_str, "cbc") == 0)
return(FKO_ENC_MODE_CBC);
else if(strcasecmp(enc_mode_str, "ecb") == 0)
return(FKO_ENC_MODE_ECB);
else if(strcasecmp(enc_mode_str, "cfb") == 0)
return(FKO_ENC_MODE_CFB);
else if(strcasecmp(enc_mode_str, "pcbc") == 0)
return(-1); /* not supported yet */
else if(strcasecmp(enc_mode_str, "ofb") == 0)
return(FKO_ENC_MODE_OFB);
else if(strcasecmp(enc_mode_str, "ctr") == 0)
return(FKO_ENC_MODE_CTR);
else if(strcasecmp(enc_mode_str, "legacy") == 0)
return(FKO_ENC_MODE_CBC_LEGACY_IV);
else
return(-1);
}
int
strtol_wrapper(const char * const str, const int min,
const int max, const int exit_upon_err, int *err)
+1
View File
@@ -38,6 +38,7 @@
int is_valid_encoded_msg_len(const int len);
int is_valid_pt_msg_len(const int len);
int is_valid_digest_len(const int len);
int enc_mode_strtoint(const char *enc_mode_str);
int strtol_wrapper(const char * const str, const int min,
const int max, const int exit_upon_err, int *is_err);
-23
View File
@@ -151,29 +151,6 @@ add_acc_expire_time_epoch(fko_srv_options_t *opts, time_t *access_expire_time, c
return;
}
/* Convert an encryption_mode string to its integer value.
*/
static int
enc_mode_strtoint(const char *enc_mode_str)
{
if(strcasecmp(enc_mode_str, "cbc") == 0)
return(FKO_ENC_MODE_CBC);
else if(strcasecmp(enc_mode_str, "ecb") == 0)
return(FKO_ENC_MODE_ECB);
else if(strcasecmp(enc_mode_str, "cfb") == 0)
return(FKO_ENC_MODE_CFB);
else if(strcasecmp(enc_mode_str, "pcbc") == 0)
return(-1); /* not supported yet */
else if(strcasecmp(enc_mode_str, "ofb") == 0)
return(FKO_ENC_MODE_OFB);
else if(strcasecmp(enc_mode_str, "ctr") == 0)
return(FKO_ENC_MODE_CTR);
else if(strcasecmp(enc_mode_str, "legacy") == 0)
return(FKO_ENC_MODE_CBC_LEGACY_IV);
else
return(-1);
}
#if FIREWALL_IPTABLES
static void
add_acc_force_nat(fko_srv_options_t *opts, acc_stanza_t *curr_acc, const char *val)