You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

axtls_aes.c 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "crypto/axtls/crypto.h"
  2. #include <string.h>
  3. #include <gpxe/crypto.h>
  4. #include <gpxe/aes.h>
  5. static int aes_setkey ( void *ctx, const void *key, size_t keylen ) {
  6. AES_CTX *aesctx = ctx;
  7. AES_MODE mode;
  8. switch ( keylen ) {
  9. case ( 128 / 8 ):
  10. mode = AES_MODE_128;
  11. break;
  12. case ( 256 / 8 ):
  13. mode = AES_MODE_256;
  14. break;
  15. default:
  16. return -EINVAL;
  17. }
  18. AES_set_key ( aesctx, key, aesctx->iv, mode );
  19. return 0;
  20. }
  21. static void aes_setiv ( void *ctx, const void *iv ) {
  22. AES_CTX *aesctx = ctx;
  23. memcpy ( aesctx->iv, iv, sizeof ( aesctx->iv ) );
  24. }
  25. static void aes_encrypt ( void *ctx, const void *data, void *dst,
  26. size_t len ) {
  27. AES_CTX *aesctx = ctx;
  28. AES_cbc_encrypt ( aesctx, data, dst, len );
  29. }
  30. static void aes_decrypt ( void *ctx, const void *data, void *dst,
  31. size_t len ) {
  32. AES_CTX *aesctx = ctx;
  33. AES_cbc_decrypt ( aesctx, data, dst, len );
  34. }
  35. struct crypto_algorithm aes_algorithm = {
  36. .name = "aes",
  37. .ctxsize = sizeof ( AES_CTX ),
  38. .blocksize = 16,
  39. .setkey = aes_setkey,
  40. .setiv = aes_setiv,
  41. .encode = aes_encrypt,
  42. .decode = aes_decrypt,
  43. };