Crypto: Mostly cosmetic changes
This commit is contained in:
parent
580529ba23
commit
876cb13356
@ -46,4 +46,8 @@ config CRYPTO_SW_AES
|
|||||||
Enable the software AES library as described in
|
Enable the software AES library as described in
|
||||||
include/nuttx/crypto/aes.h
|
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
|
endif # CRYPTO
|
||||||
|
10
crypto/aes.c
10
crypto/aes.c
@ -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
|
* 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)
|
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);
|
aes_decr(state, g_expanded_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,16 @@
|
|||||||
#include <nuttx/crypto/crypto.h>
|
#include <nuttx/crypto/crypto.h>
|
||||||
#include <nuttx/crypto/cryptodev.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
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -74,8 +84,13 @@ static const struct file_operations g_cryptodevops =
|
|||||||
cryptodev_read, /* read */
|
cryptodev_read, /* read */
|
||||||
cryptodev_write, /* write */
|
cryptodev_write, /* write */
|
||||||
0, /* seek */
|
0, /* seek */
|
||||||
cryptodev_ioctl, /* ioctl */
|
cryptodev_ioctl /* ioctl */
|
||||||
0, /* poll */
|
#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;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_CRYPTO_AES
|
||||||
case CIOCCRYPT:
|
case CIOCCRYPT:
|
||||||
{
|
{
|
||||||
FAR struct crypt_op *op = (FAR struct crypt_op *)arg;
|
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)
|
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:
|
case CRYPTO_AES_ECB:
|
||||||
return AES_CYPHER(AES_MODE_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:
|
case CRYPTO_AES_CTR:
|
||||||
return AES_CYPHER(AES_MODE_CTR);
|
return AES_CYPHER(AES_MODE_CTR);
|
||||||
|
|
||||||
# undef AES_CYPHER
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -ENOTTY;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user