Commit c6fa97a6 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

FIPS low level blocking for AES, RC4 and Camellia. This is complicated by

use of assembly language routines: rename the assembly language function
to the private_* variant unconditionally and perform tests from a small
C wrapper.
parent 24d7159a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -190,7 +190,11 @@
#define idea_set_encrypt_key	private_idea_set_encrypt_key
#define SEED_set_key	private_SEED_set_key
#define RC2_set_key	private_RC2_set_key
#define RC4_set_key	private_RC4_set_key
#define DES_set_key_unchecked	private_DES_set_key_unchecked
#define AES_set_encrypt_key	private_AES_set_encrypt_key
#define AES_set_decrypt_key	private_AES_set_decrypt_key
#define Camellia_set_key	private_Camellia_set_key
#endif

#ifndef HAVE_FORK
+5 −0
Original line number Diff line number Diff line
@@ -90,6 +90,11 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
	AES_KEY *key);

int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
	AES_KEY *key);
int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits,
	AES_KEY *key);

void AES_encrypt(const unsigned char *in, unsigned char *out,
	const AES_KEY *key);
void AES_decrypt(const unsigned char *in, unsigned char *out,
+2 −2
Original line number Diff line number Diff line
@@ -625,7 +625,7 @@ static const u32 rcon[] = {
/**
 * Expand the cipher key into the encryption key schedule.
 */
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
			AES_KEY *key) {

	u32 *rk;
@@ -726,7 +726,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
/**
 * Expand the cipher key into the decryption key schedule.
 */
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits,
			 AES_KEY *key) {

        u32 *rk;
+21 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@
 */

#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <openssl/aes.h>
#include "aes_locl.h"

@@ -62,3 +63,23 @@ const char *AES_options(void) {
        return "aes(partial)";
#endif
}

/* FIPS wrapper functions to block low level AES calls in FIPS mode */

int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
			AES_KEY *key)
	{
#ifdef OPENSSL_FIPS
	fips_cipher_abort(AES);
#endif
	return private_AES_set_encrypt_key(userKey, bits, key);
	}

int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
			AES_KEY *key)
	{
#ifdef OPENSSL_FIPS
	fips_cipher_abort(AES);
#endif
	return private_AES_set_decrypt_key(userKey, bits, key);
	}
+7 −7
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@
# but exhibits up to 10% improvement on other cores.
#
# Second version is "monolithic" replacement for aes_core.c, which in
# addition to AES_[de|en]crypt implements AES_set_[de|en]cryption_key.
# addition to AES_[de|en]crypt implements private_AES_set_[de|en]cryption_key.
# This made it possible to implement little-endian variant of the
# algorithm without modifying the base C code. Motivating factor for
# the undertaken effort was that it appeared that in tight IA-32
@@ -2854,12 +2854,12 @@ sub enckey()
    &set_label("exit");
&function_end("_x86_AES_set_encrypt_key");

# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
# int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
#                        AES_KEY *key)
&function_begin_B("AES_set_encrypt_key");
&function_begin_B("private_AES_set_encrypt_key");
	&call	("_x86_AES_set_encrypt_key");
	&ret	();
&function_end_B("AES_set_encrypt_key");
&function_end_B("private_AES_set_encrypt_key");

sub deckey()
{ my ($i,$key,$tp1,$tp2,$tp4,$tp8) = @_;
@@ -2916,9 +2916,9 @@ sub deckey()
	&mov	(&DWP(4*$i,$key),$tp1);
}

# int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
# int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits,
#                        AES_KEY *key)
&function_begin_B("AES_set_decrypt_key");
&function_begin_B("private_AES_set_decrypt_key");
	&call	("_x86_AES_set_encrypt_key");
	&cmp	("eax",0);
	&je	(&label("proceed"));
@@ -2974,7 +2974,7 @@ sub deckey()
	&jb	(&label("permute"));

	&xor	("eax","eax");			# return success
&function_end("AES_set_decrypt_key");
&function_end("private_AES_set_decrypt_key");
&asciz("AES for x86, CRYPTOGAMS by <appro\@openssl.org>");

&asm_finish();
Loading