gnutls_cipher.c gnutls_buffers.c gnutls_handshake.c gnutls_num.c \
gnutls_errors.c gnutls_algorithms.c gnutls_dh.c gnutls_kx.c \
gnutls_priority.c gnutls_hash_int.c gnutls_cipher_int.c gnutls_der.c
-libgnutls_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -ldmalloc
+libgnutls_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
void *_gnutls_cal_PRF_A(MACAlgorithm algorithm, void *secret, int secret_size, void *seed, int seed_size)
{
GNUTLS_MAC_HANDLE td1;
- void *A;
td1 = gnutls_hmac_init(algorithm, secret, secret_size);
gnutls_hmac(td1, seed, seed_size);
- A = gnutls_hmac_deinit(td1);
-
- return A;
+ return gnutls_hmac_deinit(td1);
}
GNUTLS_MAC_HANDLE td2;
opaque *ret;
void *A, *Atmp;
- int i = 0, times, copy_bytes = 0, how, blocksize, A_size;
+ int i = 0, times, how, blocksize, A_size;
void *final;
ret = secure_calloc(1, total_bytes);
for (i = 0; i < times; i++) {
td2 = gnutls_hmac_init(algorithm, secret, secret_size);
+ /* here we calculate A[i+1] */
Atmp = _gnutls_cal_PRF_A(algorithm, secret, secret_size, A, A_size);
gnutls_free(A);
A = Atmp;
gnutls_hmac(td2, seed, seed_size);
final = gnutls_hmac_deinit(td2);
- copy_bytes = blocksize;
- if ((i + 1) * copy_bytes < total_bytes) {
+ if ( (1+i) * blocksize < total_bytes) {
how = blocksize;
} else {
- how = total_bytes - (i) * copy_bytes;
+ how = total_bytes - (i) * blocksize;
}
if (how > 0) {
- memmove(&ret[i * copy_bytes], final, how);
+ memmove(&ret[i * blocksize], final, how);
}
gnutls_free(final);
}
ret = secure_calloc(1, total_bytes);
gnutls_free(s_seed);
for (i = 0; i < total_bytes; i++) {
- ret[i] = o1[i]; //^ o2[i];
+ ret[i] = o1[i] ^ o2[i];
}
secure_free(o1);
ciphertext->version.minor;
break;
case CIPHER_BLOCK:
-
if ( (ciphertext->length < blocksize) || (ciphertext->length % blocksize != 0) ) {
gnutls_assert();
return GNUTLS_E_DECRYPTION_FAILED;
#include <defines.h>
#include <gnutls_int.h>
+#include <mhash.h>
+#ifdef USE_MHASH
+/* This file handles all the internal functions that cope with hashes
+ * and hmacs. Currently it uses the functions provided by
+ * the gcrypt library that this can be easily changed.
+ */
+
+MHASH gnutls_hash_init(MACAlgorithm algorithm) {
+
+MHASH ret;
+
+ switch (algorithm) {
+ case GNUTLS_MAC_NULL:
+ ret = GNUTLS_HASH_FAILED;
+ break;
+ case GNUTLS_MAC_SHA:
+ ret = mhash_init( MHASH_SHA1);
+ if (!ret) return GNUTLS_HASH_FAILED;
+ break;
+ case GNUTLS_MAC_MD5:
+ ret = mhash_init( MHASH_MD5);
+ if (!ret) return GNUTLS_HASH_FAILED;
+ break;
+ default:
+ ret = GNUTLS_HASH_FAILED;
+ }
+
+ return ret;
+}
+
+int gnutls_hash_get_algo_len(MACAlgorithm algorithm) {
+int ret;
+
+ switch (algorithm) {
+ case GNUTLS_MAC_NULL:
+ ret = 0;
+ break;
+ case GNUTLS_MAC_SHA:
+ ret = mhash_get_block_size(MHASH_SHA1);
+ break;
+ case GNUTLS_MAC_MD5:
+ ret = mhash_get_block_size(MHASH_MD5);
+ break;
+ default:
+ ret = 0;
+ }
+
+return ret;
+
+}
+
+int gnutls_hash(GNUTLS_HASH_HANDLE handle, void* text, int textlen) {
+
+ mhash( handle, text, textlen);
+ return 0;
+}
+
+void* gnutls_hash_deinit(GNUTLS_HASH_HANDLE handle) {
+char* mac;
+int maclen;
+char* ret;
+
+ ret = mhash_end(handle);
+
+ return ret;
+}
+
+
+GNUTLS_MAC_HANDLE gnutls_hmac_init(MACAlgorithm algorithm, char* key, int keylen) {
+GNUTLS_MAC_HANDLE ret;
+
+ switch (algorithm) {
+ case GNUTLS_MAC_NULL:
+ ret = GNUTLS_MAC_FAILED;
+ break;
+ case GNUTLS_MAC_SHA:
+ ret = mhash_hmac_init( MHASH_SHA1, key, keylen, 0);
+ if (!ret) ret = GNUTLS_MAC_FAILED;
+ break;
+ case GNUTLS_MAC_MD5:
+ ret = mhash_hmac_init( MHASH_MD5, key, keylen, 0);
+ if (!ret) ret = GNUTLS_MAC_FAILED;
+ break;
+ default:
+ ret = GNUTLS_MAC_FAILED;
+ }
+
+ return ret;
+}
+
+int gnutls_hmac_get_algo_len(MACAlgorithm algorithm) {
+int ret;
+
+ switch (algorithm) {
+ case GNUTLS_MAC_NULL:
+ ret = 0;
+ break;
+ case GNUTLS_MAC_SHA:
+ ret = mhash_get_hash_pblock(MHASH_SHA1);
+ break;
+ case GNUTLS_MAC_MD5:
+ ret = mhash_get_hash_pblock(MHASH_MD5);
+ break;
+ default:
+ ret = 0;
+ }
+
+return ret;
+
+}
+
+int gnutls_hmac(GNUTLS_MAC_HANDLE handle, void* text, int textlen) {
+
+ mhash( handle, text, textlen);
+ return 0;
+
+}
+
+void* gnutls_hmac_deinit(GNUTLS_MAC_HANDLE handle) {
+char* mac;
+int maclen;
+char* ret;
+
+ ret = mhash_hmac_end(handle);
+
+ return ret;
+}
+
+#else
/* This file handles all the internal functions that cope with hashes
* and hmacs. Currently it uses the functions provided by
* the gcrypt library that this can be easily changed.
return ret;
}
+#endif /* MHASH */
{
KXAlgorithm algorithm;
GNUTLS_MPI x, X, g, p;
- int n_X, n_g, n_p;
+ size_t n_X, n_g, n_p;
uint16 _n_X, _n_g, _n_p;
uint8 *data = NULL;
uint8 *data_p;
{
KXAlgorithm algorithm;
GNUTLS_MPI x, X;
- int n_X;
+ size_t n_X;
uint16 _n_X;
uint8 *data;
int ret = 0;
int premaster_size = 0;
svoid *master;
char *random = gnutls_malloc(64);
+
#ifdef HARD_DEBUG
fprintf(stderr, "Sending client KX message\n");
#endif
+
+
memmove(random, state->security_parameters.client_random, 32);
memmove(&random[32], state->security_parameters.server_random, 32);
algorithm =
_gnutls_calc_dh_key(state->gnutls_internals.client_Y,
x,
state->gnutls_internals.client_p);
+
gcry_mpi_print(GCRYMPI_FMT_USG, NULL, &premaster_size,
state->gnutls_internals.KEY);
premaster = secure_malloc(premaster_size);
gcry_mpi_print(GCRYMPI_FMT_USG, premaster,
&premaster_size,
state->gnutls_internals.KEY);
+
/* THIS SHOULD BE DISCARDED */
gnutls_mpi_release(state->gnutls_internals.KEY);
gnutls_mpi_release(state->gnutls_internals.client_Y);
{
KXAlgorithm algorithm;
uint16 n_Y, n_g, n_p;
- int _n_Y, _n_g, _n_p;
+ size_t _n_Y, _n_g, _n_p;
uint8 *data;
int datasize;
uint8 *data_p;
uint8 *data_g;
uint8 *data_Y;
int ret = 0, i;
+unsigned char tmpy[2048];
+int ii;
+
#ifdef HARD_DEBUG
fprintf(stderr, "Receiving Server KX message\n");
#endif
{
KXAlgorithm algorithm;
uint16 n_Y;
- int _n_Y;
+ size_t _n_Y;
uint8 *data;
int datasize;
int ret = 0;
n_Y = byteswap16(n_Y);
#endif
_n_Y = n_Y;
- gcry_mpi_scan(&state->gnutls_internals.client_Y,
- GCRYMPI_FMT_USG, &data[2], &_n_Y);
+ if (gcry_mpi_scan(&state->gnutls_internals.client_Y,
+ GCRYMPI_FMT_USG, &data[2], &_n_Y)) {
+ gnutls_assert();
+ return GNUTLS_E_MPI_SCAN_FAILED;
+ }
state->gnutls_internals.KEY =
gnutls_calc_dh_key(state->
gnutls_internals.client_Y,