diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-24 16:00:54 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-24 16:00:54 +0100 |
commit | 49ecee098d062b92fcf095e05e15779c32899646 (patch) | |
tree | a02df1cfc23064d3f37a7adb15e1dafdf7a76c97 /include | |
parent | 9a64c3337cc0a5e84e9ad457eeb1d475c311e9fc (diff) | |
download | busybox-w32-49ecee098d062b92fcf095e05e15779c32899646.tar.gz busybox-w32-49ecee098d062b92fcf095e05e15779c32899646.tar.bz2 busybox-w32-49ecee098d062b92fcf095e05e15779c32899646.zip |
tls: add 2nd cipher_id, TLS_RSA_WITH_AES_128_CBC_SHA, so far it doesn't work
Good news that TLS_RSA_WITH_AES_256_CBC_SHA256 still works with new code ;)
This change adds inevitable extension to have different sized hashes and AES key sizes.
In libbb, md5_end() and shaX_end() are extended to return result size instead of void -
this helps *a lot* in tls (the cost is ~5 bytes per _end() function).
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/include/libbb.h b/include/libbb.h index ba3b1479e..b1ceb3278 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -713,18 +713,19 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC; | |||
713 | // Also mount.c and inetd.c are using gethostbyname(), | 713 | // Also mount.c and inetd.c are using gethostbyname(), |
714 | // + inet_common.c has additional IPv4-only stuff | 714 | // + inet_common.c has additional IPv4-only stuff |
715 | 715 | ||
716 | #define SHA256_INSIZE 64 | 716 | |
717 | #define SHA256_OUTSIZE 32 | 717 | #define TLS_MAX_MAC_SIZE 32 |
718 | #define AES_BLOCKSIZE 16 | 718 | #define TLS_MAX_KEY_SIZE 32 |
719 | #define AES128_KEYSIZE 16 | ||
720 | #define AES256_KEYSIZE 32 | ||
721 | struct tls_handshake_data; /* opaque */ | 719 | struct tls_handshake_data; /* opaque */ |
722 | typedef struct tls_state { | 720 | typedef struct tls_state { |
723 | int ofd; | 721 | int ofd; |
724 | int ifd; | 722 | int ifd; |
725 | 723 | ||
726 | int min_encrypted_len_on_read; | 724 | int min_encrypted_len_on_read; |
727 | uint8_t encrypt_on_write; | 725 | uint16_t cipher_id; |
726 | uint8_t encrypt_on_write; | ||
727 | unsigned MAC_size; | ||
728 | unsigned key_size; | ||
728 | 729 | ||
729 | uint8_t *outbuf; | 730 | uint8_t *outbuf; |
730 | int outbuf_size; | 731 | int outbuf_size; |
@@ -746,10 +747,12 @@ typedef struct tls_state { | |||
746 | /*uint64_t read_seq64_be;*/ | 747 | /*uint64_t read_seq64_be;*/ |
747 | uint64_t write_seq64_be; | 748 | uint64_t write_seq64_be; |
748 | 749 | ||
749 | uint8_t client_write_MAC_key[SHA256_OUTSIZE]; | 750 | uint8_t *client_write_key; |
750 | uint8_t server_write_MAC_key[SHA256_OUTSIZE]; | 751 | uint8_t *server_write_key; |
751 | uint8_t client_write_key[AES256_KEYSIZE]; | 752 | uint8_t client_write_MAC_key[TLS_MAX_MAC_SIZE]; |
752 | uint8_t server_write_key[AES256_KEYSIZE]; | 753 | uint8_t server_write_MAC_k__[TLS_MAX_MAC_SIZE]; |
754 | uint8_t client_write_k__[TLS_MAX_KEY_SIZE]; | ||
755 | uint8_t server_write_k__[TLS_MAX_KEY_SIZE]; | ||
753 | } tls_state_t; | 756 | } tls_state_t; |
754 | 757 | ||
755 | static inline tls_state_t *new_tls_state(void) | 758 | static inline tls_state_t *new_tls_state(void) |
@@ -760,6 +763,7 @@ static inline tls_state_t *new_tls_state(void) | |||
760 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; | 763 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; |
761 | void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC; | 764 | void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC; |
762 | 765 | ||
766 | |||
763 | void socket_want_pktinfo(int fd) FAST_FUNC; | 767 | void socket_want_pktinfo(int fd) FAST_FUNC; |
764 | ssize_t send_to_from(int fd, void *buf, size_t len, int flags, | 768 | ssize_t send_to_from(int fd, void *buf, size_t len, int flags, |
765 | const struct sockaddr *to, | 769 | const struct sockaddr *to, |
@@ -1799,19 +1803,23 @@ typedef struct sha3_ctx_t { | |||
1799 | } sha3_ctx_t; | 1803 | } sha3_ctx_t; |
1800 | void md5_begin(md5_ctx_t *ctx) FAST_FUNC; | 1804 | void md5_begin(md5_ctx_t *ctx) FAST_FUNC; |
1801 | void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1805 | void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1802 | void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1806 | unsigned md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1803 | void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; | 1807 | void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; |
1804 | #define sha1_hash md5_hash | 1808 | #define sha1_hash md5_hash |
1805 | void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1809 | unsigned sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1806 | void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; | 1810 | void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; |
1807 | #define sha256_hash md5_hash | 1811 | #define sha256_hash md5_hash |
1808 | #define sha256_end sha1_end | 1812 | #define sha256_end sha1_end |
1809 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; | 1813 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; |
1810 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1814 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1811 | void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1815 | unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1812 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; | 1816 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; |
1813 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1817 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1814 | void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1818 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1819 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ | ||
1820 | typedef struct md5_ctx_t md5sha_ctx_t; | ||
1821 | #define md5sha_hash md5_hash | ||
1822 | #define sha_end sha1_end | ||
1815 | 1823 | ||
1816 | extern uint32_t *global_crc32_table; | 1824 | extern uint32_t *global_crc32_table; |
1817 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 1825 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |