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
|
||||
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
|
||||
|
|
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
|
||||
****************************************************************************/
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
****************************************************************************/
|
||||
|
@ -69,13 +79,18 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd,
|
|||
|
||||
static const struct file_operations g_cryptodevops =
|
||||
{
|
||||
0, /* open */
|
||||
0, /* close */
|
||||
cryptodev_read, /* read */
|
||||
cryptodev_write, /* write */
|
||||
0, /* seek */
|
||||
cryptodev_ioctl, /* ioctl */
|
||||
0, /* poll */
|
||||
0, /* open */
|
||||
0, /* close */
|
||||
cryptodev_read, /* read */
|
||||
cryptodev_write, /* write */
|
||||
0, /* seek */
|
||||
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;
|
||||
|
@ -117,44 +133,38 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||
int encrypt;
|
||||
|
||||
switch (op->op)
|
||||
{
|
||||
case COP_ENCRYPT:
|
||||
encrypt = 1;
|
||||
break;
|
||||
{
|
||||
case COP_ENCRYPT:
|
||||
encrypt = 1;
|
||||
break;
|
||||
|
||||
case COP_DECRYPT:
|
||||
encrypt = 0;
|
||||
break;
|
||||
case COP_DECRYPT:
|
||||
encrypt = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (ses->cipher)
|
||||
{
|
||||
{
|
||||
case CRYPTO_AES_ECB:
|
||||
return AES_CYPHER(AES_MODE_ECB);
|
||||
|
||||
#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_CBC:
|
||||
return AES_CYPHER(AES_MODE_CBC);
|
||||
|
||||
case CRYPTO_AES_ECB:
|
||||
return AES_CYPHER(AES_MODE_ECB);
|
||||
case CRYPTO_AES_CTR:
|
||||
return AES_CYPHER(AES_MODE_CTR);
|
||||
|
||||
case CRYPTO_AES_CBC:
|
||||
return AES_CYPHER(AES_MODE_CBC);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue