tlsv1_record.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * TLSv1 Record Protocol
  3. * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifndef TLSV1_RECORD_H
  15. #define TLSV1_RECORD_H
  16. #include "crypto/crypto.h"
  17. #define TLS_MAX_WRITE_MAC_SECRET_LEN 20
  18. #define TLS_MAX_WRITE_KEY_LEN 32
  19. #define TLS_MAX_IV_LEN 16
  20. #define TLS_MAX_KEY_BLOCK_LEN (2 * (TLS_MAX_WRITE_MAC_SECRET_LEN + \
  21. TLS_MAX_WRITE_KEY_LEN + TLS_MAX_IV_LEN))
  22. #define TLS_SEQ_NUM_LEN 8
  23. #define TLS_RECORD_HEADER_LEN 5
  24. /* ContentType */
  25. enum {
  26. TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC = 20,
  27. TLS_CONTENT_TYPE_ALERT = 21,
  28. TLS_CONTENT_TYPE_HANDSHAKE = 22,
  29. TLS_CONTENT_TYPE_APPLICATION_DATA = 23
  30. };
  31. struct tlsv1_record_layer {
  32. u8 write_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN];
  33. u8 read_mac_secret[TLS_MAX_WRITE_MAC_SECRET_LEN];
  34. u8 write_key[TLS_MAX_WRITE_KEY_LEN];
  35. u8 read_key[TLS_MAX_WRITE_KEY_LEN];
  36. u8 write_iv[TLS_MAX_IV_LEN];
  37. u8 read_iv[TLS_MAX_IV_LEN];
  38. size_t hash_size;
  39. size_t key_material_len;
  40. size_t iv_size; /* also block_size */
  41. enum crypto_hash_alg hash_alg;
  42. enum crypto_cipher_alg cipher_alg;
  43. u8 write_seq_num[TLS_SEQ_NUM_LEN];
  44. u8 read_seq_num[TLS_SEQ_NUM_LEN];
  45. u16 cipher_suite;
  46. u16 write_cipher_suite;
  47. u16 read_cipher_suite;
  48. struct crypto_cipher *write_cbc;
  49. struct crypto_cipher *read_cbc;
  50. };
  51. int tlsv1_record_set_cipher_suite(struct tlsv1_record_layer *rl,
  52. u16 cipher_suite);
  53. int tlsv1_record_change_write_cipher(struct tlsv1_record_layer *rl);
  54. int tlsv1_record_change_read_cipher(struct tlsv1_record_layer *rl);
  55. int tlsv1_record_send(struct tlsv1_record_layer *rl, u8 content_type, u8 *buf,
  56. size_t buf_size, const u8 *payload, size_t payload_len,
  57. size_t *out_len);
  58. int tlsv1_record_receive(struct tlsv1_record_layer *rl,
  59. const u8 *in_data, size_t in_len,
  60. u8 *out_data, size_t *out_len, u8 *alert);
  61. #endif /* TLSV1_RECORD_H */