Skip to content

Commit d476a79

Browse files
cameronrichikeyasu
authored andcommitted
* Initial crack at TLS 1.2 client side only (server side is seriously broken).
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@263 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
1 parent abda243 commit d476a79

File tree

7 files changed

+263
-120
lines changed

7 files changed

+263
-120
lines changed

crypto/crypto.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007-2015, Cameron Rich
2+
* Copyright (c) 2007-2016, Cameron Rich
33
*
44
* All rights reserved.
55
*
@@ -200,6 +200,8 @@ void hmac_md5(const uint8_t *msg, int length, const uint8_t *key,
200200
int key_len, uint8_t *digest);
201201
void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key,
202202
int key_len, uint8_t *digest);
203+
void hmac_sha256(const uint8_t *msg, int length, const uint8_t *key,
204+
int key_len, uint8_t *digest);
203205

204206
/**************************************************************************
205207
* RSA declarations

crypto/hmac.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Cameron Rich
2+
* Copyright (c) 2007-2016, Cameron Rich
33
*
44
* All rights reserved.
55
*
@@ -103,3 +103,37 @@ void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key,
103103
SHA1_Update(&context, digest, SHA1_SIZE);
104104
SHA1_Final(digest, &context);
105105
}
106+
107+
/**
108+
* Perform HMAC-SHA256
109+
* NOTE: does not handle keys larger than the block size.
110+
*/
111+
void hmac_sha256(const uint8_t *msg, int length, const uint8_t *key,
112+
int key_len, uint8_t *digest)
113+
{
114+
SHA256_CTX context;
115+
uint8_t k_ipad[64];
116+
uint8_t k_opad[64];
117+
int i;
118+
119+
memset(k_ipad, 0, sizeof k_ipad);
120+
memset(k_opad, 0, sizeof k_opad);
121+
memcpy(k_ipad, key, key_len);
122+
memcpy(k_opad, key, key_len);
123+
124+
for (i = 0; i < 64; i++)
125+
{
126+
k_ipad[i] ^= 0x36;
127+
k_opad[i] ^= 0x5c;
128+
}
129+
130+
SHA256_Init(&context);
131+
SHA256_Update(&context, k_ipad, 64);
132+
SHA256_Update(&context, msg, length);
133+
SHA256_Final(digest, &context);
134+
SHA256_Init(&context);
135+
SHA256_Update(&context, k_opad, 64);
136+
SHA256_Update(&context, digest, SHA256_SIZE);
137+
SHA256_Final(digest, &context);
138+
}
139+

ssl/ssl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern "C" {
9797
#define SSL_ERROR_INVALID_PROT_MSG -261
9898
#define SSL_ERROR_INVALID_HMAC -262
9999
#define SSL_ERROR_INVALID_VERSION -263
100+
#define SSL_ERROR_UNSUPPORTED_EXTENSION -264
100101
#define SSL_ERROR_INVALID_SESSION -265
101102
#define SSL_ERROR_NO_CIPHER -266
102103
#define SSL_ERROR_BAD_CERTIFICATE -268
@@ -128,12 +129,13 @@ extern "C" {
128129
#define SSL_ALERT_DECRYPT_ERROR 51
129130
#define SSL_ALERT_INVALID_VERSION 70
130131
#define SSL_ALERT_NO_RENEGOTIATION 100
132+
#define SSL_ALERT_UNSUPPORTED_EXTENSION 110
131133

132134
/* The ciphers that are supported */
133135
#define SSL_AES128_SHA 0x2f
134136
#define SSL_AES256_SHA 0x35
135-
#define SSL_RC4_128_SHA 0x05
136-
#define SSL_RC4_128_MD5 0x04
137+
#define SSL_AES128_SHA256 0x3c
138+
#define SSL_AES256_SHA256 0x3d
137139

138140
/* build mode ids' */
139141
#define SSL_BUILD_SKELETON_MODE 0x01

0 commit comments

Comments
 (0)