aes256.c 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2016 DeNA Co., Ltd., Kazuho Oku
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to
  6. * deal in the Software without restriction, including without limitation the
  7. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. * sell copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. * IN THE SOFTWARE.
  21. */
  22. #include "aes-common.h"
  23. static int aes256ecb_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)
  24. {
  25. return aesecb_setup_crypto(ctx, is_enc, key);
  26. }
  27. static int aes256ctr_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)
  28. {
  29. return aesctr_setup_crypto(ctx, is_enc, key);
  30. }
  31. static int aead_aes256gcm_setup_crypto(ptls_aead_context_t *ctx, int is_enc, const void *key, const void *iv)
  32. {
  33. return aead_aesgcm_setup_crypto(ctx, is_enc, key, iv);
  34. }
  35. ptls_define_hash(sha384, cf_sha512_context, cf_sha384_init, cf_sha384_update, cf_sha384_digest_final);
  36. ptls_hash_algorithm_t ptls_minicrypto_sha384 = {"sha384", PTLS_SHA384_BLOCK_SIZE, PTLS_SHA384_DIGEST_SIZE, sha384_create,
  37. PTLS_ZERO_DIGEST_SHA384};
  38. ptls_define_hash(sha512, cf_sha512_context, cf_sha512_init, cf_sha512_update, cf_sha512_digest_final);
  39. ptls_hash_algorithm_t ptls_minicrypto_sha512 = {"sha512", PTLS_SHA512_BLOCK_SIZE, PTLS_SHA512_DIGEST_SIZE, sha512_create,
  40. PTLS_ZERO_DIGEST_SHA512};
  41. ptls_cipher_algorithm_t ptls_minicrypto_aes256ecb = {
  42. "AES256-ECB", PTLS_AES256_KEY_SIZE, PTLS_AES_BLOCK_SIZE, 0 /* iv size */, sizeof(struct aesecb_context_t),
  43. aes256ecb_setup_crypto};
  44. ptls_cipher_algorithm_t ptls_minicrypto_aes256ctr = {
  45. "AES256-CTR", PTLS_AES256_KEY_SIZE, 1 /* block size */, PTLS_AES_IV_SIZE, sizeof(struct aesctr_context_t),
  46. aes256ctr_setup_crypto};
  47. ptls_aead_algorithm_t ptls_minicrypto_aes256gcm = {"AES256-GCM",
  48. PTLS_AESGCM_CONFIDENTIALITY_LIMIT,
  49. PTLS_AESGCM_INTEGRITY_LIMIT,
  50. &ptls_minicrypto_aes256ctr,
  51. &ptls_minicrypto_aes256ecb,
  52. PTLS_AES256_KEY_SIZE,
  53. PTLS_AESGCM_IV_SIZE,
  54. PTLS_AESGCM_TAG_SIZE,
  55. {PTLS_TLS12_AESGCM_FIXED_IV_SIZE, PTLS_TLS12_AESGCM_RECORD_IV_SIZE},
  56. 0,
  57. 0,
  58. sizeof(struct aesgcm_context_t),
  59. aead_aes256gcm_setup_crypto};
  60. ptls_cipher_suite_t ptls_minicrypto_aes256gcmsha384 = {.id = PTLS_CIPHER_SUITE_AES_256_GCM_SHA384,
  61. .name = PTLS_CIPHER_SUITE_NAME_AES_256_GCM_SHA384,
  62. .aead = &ptls_minicrypto_aes256gcm,
  63. .hash = &ptls_minicrypto_sha384};