.deps
.libs
*.lo
+*.o
*.la
Makefile.in
Makefile
EXTRA_DIST = debug.h gnutls_compress.h defines.h gnutls_plaintext.h \
gnutls_cipher.h gnutls_buffers.h gnutls_errors.h gnutls_int.h \
gnutls_handshake.h gnutls_num.h gnutls_algorithms.h gnutls_dh.h \
- gnutls_kx.h gnutls_hash.h
+ gnutls_kx.h gnutls_hash_int.h gnutls_cipher_int.h
lib_LTLIBRARIES = libgnutls.la
libgnutls_la_SOURCES = gnutls.c gnutls_compress.c debug.c gnutls_plaintext.c \
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.c
+ gnutls_priority.c gnutls_hash_int.c gnutls_cipher_int.c
libgnutls_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
#include "gnutls_cipher.h"
#include "gnutls_buffers.h"
#include "gnutls_handshake.h"
-#include "gnutls_hash.h"
+#include "gnutls_hash_int.h"
+#include "gnutls_cipher_int.h"
/* This function should check if we support the version of the peer.
* However now we only support version 3.1
gnutls_free((*state)->gnutls_internals.buffer_handshake);
if ((*state)->connection_state.read_cipher_state != NULL)
- gcry_cipher_close((*state)->
+ gnutls_cipher_deinit((*state)->
connection_state.read_cipher_state);
if ((*state)->connection_state.write_cipher_state != NULL)
- gcry_cipher_close((*state)->
+ gnutls_cipher_deinit((*state)->
connection_state.write_cipher_state);
secure_free((*state)->cipher_specs.server_write_mac_secret);
#include "gnutls_compress.h"
#include "gnutls_cipher.h"
#include "gnutls_algorithms.h"
-#include "gnutls_hash.h"
+#include "gnutls_hash_int.h"
+#include "gnutls_cipher_int.h"
int _gnutls_make_mul(int x, int y)
{
state->security_parameters.cipher_type =
CIPHER_STREAM;
}
- state->security_parameters.is_exportable =
- EXPORTABLE_FALSE;
+ state->security_parameters.is_exportable = EXPORTABLE_FALSE;
state->security_parameters.key_material_length =
state->security_parameters.key_size =
_gnutls_cipher_get_key_size(algo);
return GNUTLS_E_UNKNOWN_MAC_ALGORITHM;
}
- switch (state->security_parameters.bulk_cipher_algorithm) {
- case GNUTLS_NULL:
- state->connection_state.read_cipher_state = NULL;
- state->connection_state.write_cipher_state = NULL;
- break;
- case GNUTLS_3DES:
- state->connection_state.read_cipher_state =
- gcry_cipher_open(GCRY_CIPHER_3DES,
- GCRY_CIPHER_MODE_CBC, 0);
- state->connection_state.write_cipher_state =
- gcry_cipher_open(GCRY_CIPHER_3DES,
- GCRY_CIPHER_MODE_CBC, 0);
- break;
- default:
- return GNUTLS_E_UNKNOWN_CIPHER;
- }
-
-
switch (state->security_parameters.entity) {
case GNUTLS_SERVER:
- if (state->connection_state.write_cipher_state != NULL) {
- rc =
- gcry_cipher_setkey(state->
- connection_state.write_cipher_state,
- state->
- cipher_specs.server_write_key,
- state->
- security_parameters.key_size);
- gcry_cipher_setiv(state->
- connection_state.write_cipher_state,
- state->
- cipher_specs.server_write_IV,
- state->
- security_parameters.IV_size);
-
+ state->connection_state.write_cipher_state =
+ gnutls_cipher_init( state->security_parameters.bulk_cipher_algorithm,
+ state->cipher_specs.server_write_key,
+ state->security_parameters.key_size,
+ state->cipher_specs.server_write_IV,
+ state->security_parameters.IV_size);
+ if (state->connection_state.write_cipher_state==GNUTLS_CIPHER_FAILED && state->security_parameters.bulk_cipher_algorithm!=GNUTLS_NULL) {
+ return GNUTLS_E_UNKNOWN_CIPHER;
}
+
if (state->connection_state.mac_secret_size > 0) {
memmove(state->connection_state.read_mac_secret,
state->cipher_specs.
state->connection_state.mac_secret_size);
}
- if (state->connection_state.read_cipher_state != NULL) {
- rc =
- gcry_cipher_setkey(state->
- connection_state.read_cipher_state,
- state->
- cipher_specs.client_write_key,
- state->
- security_parameters.key_size);
- gcry_cipher_setiv(state->
- connection_state.read_cipher_state,
- state->
- cipher_specs.client_write_IV,
- state->
- security_parameters.IV_size);
+ state->connection_state.read_cipher_state =
+ gnutls_cipher_init( state->security_parameters.bulk_cipher_algorithm,
+ state->cipher_specs.client_write_key,
+ state->security_parameters.key_size,
+ state->cipher_specs.client_write_IV,
+ state->security_parameters.IV_size);
+ if (state->connection_state.read_cipher_state==GNUTLS_CIPHER_FAILED && state->security_parameters.bulk_cipher_algorithm!=GNUTLS_NULL) {
+ return GNUTLS_E_UNKNOWN_CIPHER;
}
+
break;
case GNUTLS_CLIENT:
- if (state->connection_state.read_cipher_state != NULL) {
- rc =
- gcry_cipher_setkey(state->
- connection_state.read_cipher_state,
- state->
- cipher_specs.server_write_key,
- state->
- security_parameters.key_size);
- gcry_cipher_setiv(state->
- connection_state.read_cipher_state,
- state->
- cipher_specs.server_write_IV,
- state->
- security_parameters.IV_size);
-
+ state->connection_state.read_cipher_state =
+ gnutls_cipher_init( state->security_parameters.bulk_cipher_algorithm,
+ state->cipher_specs.server_write_key,
+ state->security_parameters.key_size,
+ state->cipher_specs.server_write_IV,
+ state->security_parameters.IV_size);
+ if (state->connection_state.read_cipher_state==GNUTLS_CIPHER_FAILED && state->security_parameters.bulk_cipher_algorithm!=GNUTLS_NULL) {
+ return GNUTLS_E_UNKNOWN_CIPHER;
}
+
if (state->connection_state.mac_secret_size > 0) {
memmove(state->connection_state.read_mac_secret,
state->cipher_specs.
state->connection_state.mac_secret_size);
}
- if (state->connection_state.write_cipher_state != NULL) {
- gcry_cipher_setiv(state->
- connection_state.write_cipher_state,
- state->
- cipher_specs.client_write_IV,
- state->
- security_parameters.IV_size);
- rc =
- gcry_cipher_setkey(state->
- connection_state.write_cipher_state,
- state->
- cipher_specs.client_write_key,
- state->
- security_parameters.key_size);
+ state->connection_state.write_cipher_state =
+ gnutls_cipher_init( state->security_parameters.bulk_cipher_algorithm,
+ state->cipher_specs.client_write_key,
+ state->security_parameters.key_size,
+ state->cipher_specs.client_write_IV,
+ state->security_parameters.IV_size);
+ if (state->connection_state.write_cipher_state==GNUTLS_CIPHER_FAILED && state->security_parameters.bulk_cipher_algorithm!=GNUTLS_NULL) {
+ return GNUTLS_E_UNKNOWN_CIPHER;
}
break;
MAC = gnutls_hmac_deinit(td);
}
switch (state->security_parameters.cipher_type) {
- case CIPHER_STREAM:
- switch (state->security_parameters.bulk_cipher_algorithm) {
- case GNUTLS_NULL:
+ case CIPHER_STREAM:
length =
compressed->length +
state->connection_state.mac_secret_size;
memmove(data, content, compressed->length);
memmove(&data[compressed->length], MAC,
state->connection_state.mac_secret_size);
+
+ gnutls_cipher_encrypt(state->
+ connection_state.write_cipher_state,
+ data, length);
ciphertext->fragment = data;
ciphertext->length = length;
ciphertext->type = compressed->type;
compressed->version.major;
ciphertext->version.minor =
compressed->version.minor;
- break;
- default:
- gnutls_free(*cipher);
- gnutls_free(content);
- return GNUTLS_E_UNKNOWN_CIPHER;
- }
break;
case CIPHER_BLOCK:
- switch (state->security_parameters.bulk_cipher_algorithm) {
- case GNUTLS_3DES:
-
rand = gcry_random_bytes(1, GCRY_STRONG_RANDOM);
- rand[0] = rand[0] % (255-_gnutls_cipher_get_block_size(GNUTLS_3DES));
+ rand[0] = rand[0] % (255-_gnutls_cipher_get_block_size(state->security_parameters.bulk_cipher_algorithm));
length =
compressed->length +
length =
_gnutls_make_mul(length,
_gnutls_cipher_get_block_size
- (GNUTLS_3DES));
+ (state->security_parameters.bulk_cipher_algorithm));
pad =
length - compressed->length -
state->connection_state.mac_secret_size - 1;
gnutls_free(padding);
- gcry_cipher_encrypt(state->
+ gnutls_cipher_encrypt(state->
connection_state.write_cipher_state,
- data, length, data, length);
+ data, length);
ciphertext->fragment = data;
ciphertext->length = length;
compressed->version.minor;
gcry_free(rand);
- break;
- default:
- gnutls_free(*cipher);
- gnutls_free(content);
- return GNUTLS_E_UNKNOWN_CIPHER;
- }
break;
default:
gnutls_free(*cipher);
switch (state->security_parameters.cipher_type) {
case CIPHER_STREAM:
- switch (state->security_parameters.bulk_cipher_algorithm) {
- case GNUTLS_NULL:
length =
ciphertext->length -
state->connection_state.mac_secret_size;
ciphertext->version.major;
compressed->version.minor =
ciphertext->version.minor;
- break;
- default:
- gnutls_free(*compress);
- gnutls_free(content);
- return GNUTLS_E_UNKNOWN_CIPHER;
-
- }
break;
case CIPHER_BLOCK:
- switch (state->security_parameters.bulk_cipher_algorithm) {
- case GNUTLS_3DES:
- gcry_cipher_decrypt(state->
+ gnutls_cipher_decrypt(state->
connection_state.read_cipher_state,
- content, ciphertext->length,
content, ciphertext->length);
pad = content[ciphertext->length - 1]; /* pad */
ciphertext->version.major;
compressed->version.minor =
ciphertext->version.minor;
-
- break;
- default:
- gnutls_free(*compress);
- gnutls_free(content);
- return GNUTLS_E_UNKNOWN_CIPHER;
- }
break;
default:
gnutls_free(*compress);
/* Taken from gsti */
static const uint8 diffie_hellman_group1_prime[130] = { 0x04, 0x00,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA,
- 0xA2,
- 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C,
- 0xD1,
- 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE,
- 0xA6,
- 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04,
- 0xDD,
- 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A,
- 0x6D,
- 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2,
- 0x45,
- 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42,
- 0xE9,
- 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7,
- 0xED,
- 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24,
- 0x11,
- 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53,
- 0x81,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
+ 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
+ 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
+ 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
+ 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
+ 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
+ 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
+ 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
+ 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
+ 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
his_key = X ^ y mod p;
// generate our secret and the public value for it
- X = _gnutls_calc_dh_secret(&x);
+ X = gnutls_calc_dh_secret(&x);
// now we can calculate the shared secret
- key = _gnutls_calc_dh_key(Y, x);
- mpi_release(x);
- mpi_release(g);
+ key = gnutls_calc_dh_key(Y, x);
+ gnutls_mpi_release(x);
+ gnutls_mpi_release(g);
*/
#define E_SIZE 1024
#include "gnutls_kx.h"
#include "gnutls_handshake.h"
#include "gnutls_num.h"
-#include "gnutls_hash.h"
+#include "gnutls_hash_int.h"
#ifdef DEBUG
#define ERR(x, y) fprintf(stderr, "GNUTLS Error: %s (%d)\n", x,y)
+++ /dev/null
-/*
- * Copyright (C) 2000 Nikos Mavroyanopoulos
- *
- * This file is part of GNUTLS.
- *
- * GNUTLS is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GNUTLS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <defines.h>
-#include <gnutls_int.h>
-
-GNUTLS_HASH_HANDLE gnutls_hash_init(MACAlgorithm algorithm) {
-GNUTLS_HASH_HANDLE ret;
-
- switch (algorithm) {
- case GNUTLS_MAC_NULL:
- ret = GNUTLS_HASH_FAILED;
- break;
- case GNUTLS_MAC_SHA:
- ret = gcry_md_open( GCRY_MD_SHA1, 0);
- if (!ret) return GNUTLS_HASH_FAILED;
- break;
- case GNUTLS_MAC_MD5:
- ret = gcry_md_open( GCRY_MD_MD5, 0);
- 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 = gcry_md_get_algo_dlen( GCRY_MD_SHA1);
- break;
- case GNUTLS_MAC_MD5:
- ret = gcry_md_get_algo_dlen( GCRY_MD_MD5);
- break;
- default:
- ret = 0;
- }
-
-return ret;
-
-}
-
-int gnutls_hash(GNUTLS_HASH_HANDLE handle, void* text, int textlen) {
-
- gcry_md_write( handle, text, textlen);
- return 0;
-}
-
-void* gnutls_hash_deinit(GNUTLS_HASH_HANDLE handle) {
-char* mac;
-int maclen;
-char* ret;
-
- maclen = gcry_md_get_algo_dlen(gcry_md_get_algo(handle));
- ret = gnutls_malloc(maclen);
-
- gcry_md_final(handle);
- mac = gcry_md_read(handle,0);
- memmove( ret, mac, maclen);
- gcry_md_close(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 = gcry_md_open( GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
- if (!ret) return GNUTLS_MAC_FAILED;
- break;
- case GNUTLS_MAC_MD5:
- ret = gcry_md_open( GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
- if (!ret) return GNUTLS_MAC_FAILED;
- break;
- default:
- ret = GNUTLS_MAC_FAILED;
- }
- gcry_md_setkey(ret, key, keylen);
-
- 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 = gcry_md_get_algo_dlen( GCRY_MD_SHA1);
- break;
- case GNUTLS_MAC_MD5:
- ret = gcry_md_get_algo_dlen( GCRY_MD_MD5);
- break;
- default:
- ret = 0;
- }
-
-return ret;
-
-}
-
-int gnutls_hmac(GNUTLS_MAC_HANDLE handle, void* text, int textlen) {
-
- gcry_md_write( handle, text, textlen);
- return 0;
-
-}
-
-void* gnutls_hmac_deinit(GNUTLS_MAC_HANDLE handle) {
-char* mac;
-int maclen;
-char* ret;
-
- maclen = gcry_md_get_algo_dlen(gcry_md_get_algo(handle));
- ret = gnutls_malloc( maclen);
-
- gcry_md_final(handle);
- mac = gcry_md_read(handle,0);
- memmove( ret, mac, maclen);
- gcry_md_close(handle);
-
- return ret;
-}
-
+++ /dev/null
-GNUTLS_MAC_HANDLE gnutls_hmac_init(MACAlgorithm algorithm, char* key, int keylen);
-int gnutls_hmac_get_algo_len(MACAlgorithm algorithm);
-int gnutls_hmac(GNUTLS_HASH_HANDLE handle, void* text, int textlen);
-void* gnutls_hmac_deinit(GNUTLS_HASH_HANDLE handle);
-
-GNUTLS_HASH_HANDLE gnutls_hash_init(MACAlgorithm algorithm);
-int gnutls_hash_get_algo_len(MACAlgorithm algorithm);
-int gnutls_hash(GNUTLS_HASH_HANDLE handle, void* text, int textlen);
-void* gnutls_hash_deinit(GNUTLS_HASH_HANDLE handle);
-
#define GNUTLS_HASH_FAILED NULL
#define GNUTLS_MAC_FAILED NULL
+/* for symmetric ciphers */
+#define GNUTLS_CIPHER_HANDLE GCRY_CIPHER_HD
+#define GNUTLS_CIPHER_FAILED NULL
+
+/* for big numbers support */ /* FIXME */
+#define GNUTLS_MPI MPI
+#define gnutls_mpi_release mpi_release
+
#define svoid void /* for functions that allocate using secure_free */
#define secure_free(x) if (x!=NULL) free(x)
#define secure_malloc malloc
GNUTLS_Version version;
opaque* read_compression_state;
opaque* write_compression_state;
- GCRY_CIPHER_HD write_cipher_state;
- GCRY_CIPHER_HD read_cipher_state;
+ GNUTLS_CIPHER_HANDLE write_cipher_state;
+ GNUTLS_CIPHER_HANDLE read_cipher_state;
opaque* read_mac_secret;
opaque* write_mac_secret;
uint8 mac_secret_size;
int _gnutls_send_server_kx_message(int cd, GNUTLS_STATE state)
{
KXAlgorithm algorithm;
- MPI x, X, g, p;
+ GNUTLS_MPI x, X, g, p;
int n_X, n_g, n_p;
uint16 _n_X, _n_g, _n_p;
uint8 *data=NULL;
data_p = &data[0];
gcry_mpi_print(GCRYMPI_FMT_STD, &data_p[2],
&n_p, p);
- mpi_release(p);
+ gnutls_mpi_release(p);
_n_p = n_p;
data_g = &data_p[2+n_p];
gcry_mpi_print(GCRYMPI_FMT_STD, &data_g[2],
&n_g, g);
- mpi_release(g);
+ gnutls_mpi_release(g);
_n_g = n_g;
#ifndef WORDS_BIGENDIAN
data_X = &data_g[2+n_g];
gcry_mpi_print(GCRYMPI_FMT_STD, &data_X[2],
&n_X, X);
- mpi_release(X);
+ gnutls_mpi_release(X);
_n_X = n_X;
#ifndef WORDS_BIGENDIAN
int _gnutls_send_client_kx_message(int cd, GNUTLS_STATE state)
{
KXAlgorithm algorithm;
- MPI x, X;
+ GNUTLS_MPI x, X;
int n_X;
uint16 _n_X;
uint8 *data;
data[0] = 1; /* extern */
- mpi_release(X);
+ gnutls_mpi_release(X);
_n_X = n_X;
#ifndef WORDS_BIGENDIAN
&premaster_size, state->gnutls_internals.KEY);
/* THIS SHOULD BE DISCARDED */
- mpi_release(state->gnutls_internals.KEY);
- mpi_release(state->gnutls_internals.client_Y);
- mpi_release(state->gnutls_internals.client_p);
- mpi_release(state->gnutls_internals.client_g);
+ gnutls_mpi_release(state->gnutls_internals.KEY);
+ gnutls_mpi_release(state->gnutls_internals.client_Y);
+ gnutls_mpi_release(state->gnutls_internals.client_p);
+ gnutls_mpi_release(state->gnutls_internals.client_g);
state->gnutls_internals.KEY=NULL;
state->gnutls_internals.client_Y=NULL;
state->gnutls_internals.client_p=NULL;
&premaster_size, state->gnutls_internals.KEY);
/* THESE SHOULD BE DISCARDED */
- mpi_release(state->gnutls_internals.KEY);
- mpi_release(state->gnutls_internals.client_Y);
- mpi_release(state->gnutls_internals.dh_secret);
+ gnutls_mpi_release(state->gnutls_internals.KEY);
+ gnutls_mpi_release(state->gnutls_internals.client_Y);
+ gnutls_mpi_release(state->gnutls_internals.dh_secret);
state->gnutls_internals.KEY=NULL;
state->gnutls_internals.client_Y=NULL;
state->gnutls_internals.dh_secret=NULL;