mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 10:58:49 +08:00
Crypto: Mostly cosmetic changes
This commit is contained in:
parent
580529ba23
commit
876cb13356
3 changed files with 57 additions and 37 deletions
|
@ -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
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -69,13 +79,18 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd,
|
||||||
|
|
||||||
static const struct file_operations g_cryptodevops =
|
static const struct file_operations g_cryptodevops =
|
||||||
{
|
{
|
||||||
0, /* open */
|
0, /* open */
|
||||||
0, /* close */
|
0, /* close */
|
||||||
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;
|
||||||
|
@ -117,44 +133,38 @@ static int cryptodev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||||
int encrypt;
|
int encrypt;
|
||||||
|
|
||||||
switch (op->op)
|
switch (op->op)
|
||||||
{
|
{
|
||||||
case COP_ENCRYPT:
|
case COP_ENCRYPT:
|
||||||
encrypt = 1;
|
encrypt = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COP_DECRYPT:
|
case COP_DECRYPT:
|
||||||
encrypt = 0;
|
encrypt = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ses->cipher)
|
switch (ses->cipher)
|
||||||
{
|
{
|
||||||
|
case CRYPTO_AES_ECB:
|
||||||
|
return AES_CYPHER(AES_MODE_ECB);
|
||||||
|
|
||||||
#if defined(CONFIG_CRYPTO_AES)
|
case CRYPTO_AES_CBC:
|
||||||
# define AES_CYPHER(mode) aes_cypher(op->dst, op->src, op->len, op->iv, ses->key, ses->keylen, mode, encrypt)
|
return AES_CYPHER(AES_MODE_CBC);
|
||||||
|
|
||||||
case CRYPTO_AES_ECB:
|
case CRYPTO_AES_CTR:
|
||||||
return AES_CYPHER(AES_MODE_ECB);
|
return AES_CYPHER(AES_MODE_CTR);
|
||||||
|
|
||||||
case CRYPTO_AES_CBC:
|
default:
|
||||||
return AES_CYPHER(AES_MODE_CBC);
|
return -EINVAL;
|
||||||
|
}
|
||||||
case CRYPTO_AES_CTR:
|
}
|
||||||
return AES_CYPHER(AES_MODE_CTR);
|
|
||||||
|
|
||||||
# undef AES_CYPHER
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -ENOTTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue