aes128.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 aes128ecb_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 aes128ctr_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_aes128gcm_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(sha256, cf_sha256_context, cf_sha256_init, cf_sha256_update, cf_sha256_digest_final);
  36. ptls_hash_algorithm_t ptls_minicrypto_sha256 = {"sha256", PTLS_SHA256_BLOCK_SIZE, PTLS_SHA256_DIGEST_SIZE, sha256_create,
  37. PTLS_ZERO_DIGEST_SHA256};
  38. ptls_cipher_algorithm_t ptls_minicrypto_aes128ecb = {
  39. "AES128-ECB", PTLS_AES128_KEY_SIZE, PTLS_AES_BLOCK_SIZE, 0 /* iv size */, sizeof(struct aesecb_context_t),
  40. aes128ecb_setup_crypto};
  41. ptls_cipher_algorithm_t ptls_minicrypto_aes128ctr = {
  42. "AES128-CTR", PTLS_AES128_KEY_SIZE, 1 /* block size */, PTLS_AES_IV_SIZE, sizeof(struct aesctr_context_t),
  43. aes128ctr_setup_crypto};
  44. ptls_aead_algorithm_t ptls_minicrypto_aes128gcm = {"AES128-GCM",
  45. PTLS_AESGCM_CONFIDENTIALITY_LIMIT,
  46. PTLS_AESGCM_INTEGRITY_LIMIT,
  47. &ptls_minicrypto_aes128ctr,
  48. &ptls_minicrypto_aes128ecb,
  49. PTLS_AES128_KEY_SIZE,
  50. PTLS_AESGCM_IV_SIZE,
  51. PTLS_AESGCM_TAG_SIZE,
  52. {PTLS_TLS12_AESGCM_FIXED_IV_SIZE, PTLS_TLS12_AESGCM_RECORD_IV_SIZE},
  53. 0,
  54. 0,
  55. sizeof(struct aesgcm_context_t),
  56. aead_aes128gcm_setup_crypto};
  57. ptls_cipher_suite_t ptls_minicrypto_aes128gcmsha256 = {.id = PTLS_CIPHER_SUITE_AES_128_GCM_SHA256,
  58. .name = PTLS_CIPHER_SUITE_NAME_AES_128_GCM_SHA256,
  59. .aead = &ptls_minicrypto_aes128gcm,
  60. .hash = &ptls_minicrypto_sha256};