X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_keyexpimp.c;h=7c28a03029011c946c1c15324de9063305a397ba;hb=7ef27e2d62a45c94a462f6c08f4fdda70c41944c;hp=e8ee1ebedce5e9a129f7d1874a78109a6fc73234;hpb=a418dfa28b4c3432a6da7d01adc1038789ce209c;p=openssl-gost%2Fengine.git diff --git a/gost_keyexpimp.c b/gost_keyexpimp.c index e8ee1eb..7c28a03 100644 --- a/gost_keyexpimp.c +++ b/gost_keyexpimp.c @@ -1,7 +1,12 @@ +#ifdef _WIN32 +#include +#else #include +#endif #include #include #include +#include #include "gost_lcl.h" #include "e_gost_err.h" @@ -34,6 +39,11 @@ int gost_kexp15(const unsigned char *shared_key, const int shared_len, goto err; } + if (shared_len + mac_len > (unsigned int)(*out_len)) { + GOSTerr(GOST_F_GOST_KEXP15, ERR_R_INTERNAL_ERROR); + goto err; + } + /* we expect IV of half length */ memset(iv_full, 0, 16); memcpy(iv_full, iv, ivlen); @@ -111,6 +121,16 @@ int gost_kimp15(const unsigned char *expkey, const size_t expkeylen, goto err; } + if (expkeylen > sizeof(out)) { + GOSTerr(GOST_F_GOST_KIMP15, ERR_R_INTERNAL_ERROR); + goto err; + } + + if (ivlen > 16) { + GOSTerr(GOST_F_GOST_KIMP15, ERR_R_INTERNAL_ERROR); + goto err; + } + /* we expect IV of half length */ memset(iv_full, 0, 16); memcpy(iv_full, iv, ivlen); @@ -172,7 +192,7 @@ int gost_kdftree2012_256(unsigned char *keyout, size_t keyout_len, int iters, i = 0; unsigned char zero = 0; unsigned char *ptr = keyout; - HMAC_CTX *ctx = NULL; + HMAC_CTX *ctx; unsigned char *len_ptr = NULL; uint32_t len_repr = htonl(keyout_len * 8); size_t len_repr_len = 4; @@ -226,17 +246,10 @@ int gost_kdftree2012_256(unsigned char *keyout, size_t keyout_len, int gost_tlstree(int cipher_nid, const unsigned char *in, unsigned char *out, const unsigned char *tlsseq) { -#ifndef L_ENDIAN - uint64_t gh_c1 = 0xFFFFFFFF00000000, gh_c2 = 0xFFFFFFFFFFF80000, - gh_c3 = 0xFFFFFFFFFFFFFFC0; - uint64_t mg_c1 = 0xFFFFFFC000000000, mg_c2 = 0xFFFFFFFFFE000000, - mg_c3 = 0xFFFFFFFFFFFFF000; -#else uint64_t gh_c1 = 0x00000000FFFFFFFF, gh_c2 = 0x0000F8FFFFFFFFFF, gh_c3 = 0xC0FFFFFFFFFFFFFF; uint64_t mg_c1 = 0x00000000C0FFFFFF, mg_c2 = 0x000000FEFFFFFFFF, mg_c3 = 0x00F0FFFFFFFFFFFF; -#endif uint64_t c1, c2, c3; uint64_t seed1, seed2, seed3; uint64_t seq; @@ -256,7 +269,11 @@ int gost_tlstree(int cipher_nid, const unsigned char *in, unsigned char *out, default: return 0; } +#ifndef L_ENDIAN + BUF_reverse((unsigned char *)&seq, tlsseq, 8); +#else memcpy(&seq, tlsseq, 8); +#endif seed1 = seq & c1; seed2 = seq & c2; seed3 = seq & c3;