Crypto: Mostly cosmetic changes

This commit is contained in:
Gregory Nutt 2015-11-16 16:10:01 -06:00
parent 580529ba23
commit 876cb13356
3 changed files with 57 additions and 37 deletions

View File

@ -46,4 +46,8 @@ config CRYPTO_SW_AES
Enable the software AES library as described in
include/nuttx/crypto/aes.h
TODO: Adapt interfaces so that they are consistent with H/W AES
implemenations. This needs to support up_aesinitialize() and
aes_cypher() per include/nuttx/crypto/crypto.h.
endif # CRYPTO

View File

@ -34,6 +34,11 @@
*
****************************************************************************/
/* TODO: Adapt interfaces so that they are consistent with H/W AES
* implemenations. This needs to support up_aesinitialize() and
* aes_cypher() per include/nuttx/crypto/crypto.h.
*/
/****************************************************************************
* Included Files
****************************************************************************/
@ -582,7 +587,8 @@ void aes_encrypt(FAR uint8_t *state, FAR const uint8_t *key)
void aes_decrypt(FAR uint8_t *state, FAR const uint8_t *key)
{
expand_key(g_expanded_key, key); /* Expand the key into 176 bytes */
/* Expand the key into 176 bytes */
expand_key(g_expanded_key, key);
aes_decr(state, g_expanded_key);
}

View File

@ -50,6 +50,16 @@
#include <nuttx/crypto/crypto.h>
#include <nuttx/crypto/cryptodev.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_CRYPTO_AES
# define AES_CYPHER(mode) \
aes_cypher(op->dst, op->src, op->len, op->iv, ses->key, ses->keylen, \
mode, encrypt)
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@ -74,8 +84,13 @@ static const struct file_operations g_cryptodevops =
cryptodev_read, /* read */
cryptodev_write, /* write */
0, /* seek */
cryptodev_ioctl, /* ioctl */
0, /* poll */
cryptodev_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
, 0 /* poll */
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
, 0 /* unlink */
#endif
};
/****************************************************************************
@ -110,6 +125,7 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
return OK;
}
#ifdef CONFIG_CRYPTO_AES
case CIOCCRYPT:
{
FAR struct crypt_op *op = (FAR struct crypt_op *)arg;
@ -132,10 +148,6 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch (ses->cipher)
{
#if defined(CONFIG_CRYPTO_AES)
# define AES_CYPHER(mode) aes_cypher(op->dst, op->src, op->len, op->iv, ses->key, ses->keylen, mode, encrypt)
case CRYPTO_AES_ECB:
return AES_CYPHER(AES_MODE_ECB);
@ -145,16 +157,14 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case CRYPTO_AES_CTR:
return AES_CYPHER(AES_MODE_CTR);
# undef AES_CYPHER
default:
return -EINVAL;
}
}
#endif
default:
return -EINVAL;
}
}
default:
return -EINVAL;
return -ENOTTY;
}
}