140 #ifndef OPENSSL_NO_COMP
152 static int tls1_P_hash(
const EVP_MD *md,
const unsigned char *sec,
154 const void *seed1,
int seed1_len,
155 const void *seed2,
int seed2_len,
156 const void *seed3,
int seed3_len,
157 const void *seed4,
int seed4_len,
158 const void *seed5,
int seed5_len,
159 unsigned char *out,
int olen)
246 static int tls1_PRF(
long digest_mask,
247 const void *seed1,
int seed1_len,
248 const void *seed2,
int seed2_len,
249 const void *seed3,
int seed3_len,
250 const void *seed4,
int seed4_len,
251 const void *seed5,
int seed5_len,
252 const unsigned char *sec,
int slen,
254 unsigned char *out2,
int olen)
257 const unsigned char *S1;
279 if (!tls1_P_hash(md ,S1,len+(slen&1),
280 seed1,seed1_len,seed2,seed2_len,seed3,seed3_len,seed4,seed4_len,seed5,seed5_len,
284 for (i=0; i<olen; i++)
294 static int tls1_generate_key_block(
SSL *s,
unsigned char *km,
295 unsigned char *tmp,
int num)
306 printf(
"tls1_generate_key_block() ==> %d byte master_key =\n\t",
321 static const unsigned char empty[]=
"";
322 unsigned char *
p,*mac_secret;
323 unsigned char *exp_label;
328 unsigned char *ms,*
key,*iv;
332 #ifndef OPENSSL_NO_COMP
337 int *mac_secret_size;
340 int is_export,n,i,j,
k,exp_label_len,cl;
347 #ifndef OPENSSL_NO_COMP
352 printf(
"tls1_change_cipher_state(which= %d) w/\n", which);
353 printf(
"\talg= %ld/%ld, comp= %p\n",
357 printf(
"\tevp_cipher == %p ==? &d_cbc_ede_cipher3\n", c);
358 printf(
"\tevp_cipher: nid, blksz= %d, %d, keylen=%d, ivlen=%d\n",
364 printf(
"%02x", key_block[i]); printf(
"\n");
384 #ifndef OPENSSL_NO_COMP
426 #ifndef OPENSSL_NO_COMP
468 key= &(p[ n]); n+=j+j;
469 iv= &(p[ n]); n+=k+k;
477 ms= &(p[ n]); n+=i+j;
478 key= &(p[ n]); n+=j+k;
491 memcpy(mac_secret,ms,i);
496 mac_secret,*mac_secret_size);
501 printf(
"which = %04X\nmac key=",which);
502 {
int z;
for (z=0; z<i; z++) printf(
"%02X%c",ms[z],((z+1)%16)?
' ':
'\n'); }
510 exp_label,exp_label_len,
525 empty,0,iv1,iv2,k*2))
538 printf(
"EVP_CipherInit_ex(dd,c,key=,iv=,which)\n");
539 printf(
"\tkey= ");
for (i=0; i<c->
key_len; i++) printf(
"%02x", key[i]);
541 printf(
"\t iv= ");
for (i=0; i<c->
iv_len; i++) printf(
"%02x", iv[i]);
557 *mac_secret_size,mac_secret);
560 printf(
"which = %04X\nkey=",which);
563 {
int z;
for (z=0; z<k; z++) printf(
"%02X%c",iv[z],((z+1)%16)?
' ':
'\n'); }
580 unsigned char *p1,*p2=NULL;
585 int mac_type=
NID_undef,mac_secret_size=0;
589 printf (
"tls1_setup_key_block()\n");
626 printf(
"client random\n");
628 printf(
"server random\n");
630 printf(
"pre-master\n");
633 if (!tls1_generate_key_block(s,p1,p2,num))
636 printf(
"\nkey block\n");
637 {
int z;
for (z=0; z<
num; z++) printf(
"%02X%c",p1[z],((z+1)%16)?
' ':
'\n'); }
653 #ifndef OPENSSL_NO_RC4
675 int bs,i,ii,j,
k,pad=0;
706 "%s:%d: rec->data != rec->input\n",
729 printf(
"tls1_enc(%d)\n", send);
732 if ((s->
session == NULL) || (ds == NULL) ||
745 unsigned char buf[13],*seq;
751 unsigned char dtlsseq[9],*
p=dtlsseq;
755 memcpy(buf,dtlsseq,8);
763 if (seq[i] != 0)
break;
768 buf[9]=(
unsigned char)(s->
version>>8);
769 buf[10]=(
unsigned char)(s->
version);
779 else if ((bs != 1) && send)
792 for (k=(
int)l; k<(int)(l+i); k++)
801 printf(
"EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n",
803 printf(
"\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n",
810 printf(
"\trec->input=");
811 for (ui=0; ui<l; ui++) printf(
" %02x", rec->
input[ui]);
818 if (l == 0 || l%bs != 0)
843 printf(
"\trec->data=");
845 printf(
" %02x", rec->
data[i]); printf(
"\n");
849 if ((bs != 1) && !send)
865 "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1))
880 for (j=(
int)(l-i); j<(int)l; j++)
882 if (rec->
data[j] != ii)
892 if (bs > (
int)rec->
length)
935 const char *str,
int slen,
unsigned char *out)
940 unsigned char *
q,buf2[12];
959 if (hashsize < 0 || hashsize > (
int)(
sizeof buf - (
size_t)(q-buf)))
968 if (i != (
unsigned int)hashsize)
976 str,slen, buf,(
int)(q-buf), NULL,0, NULL,0, NULL,0,
978 out,buf2,
sizeof buf2))
996 unsigned char buf[5];
1018 buf[1]=(
unsigned char)(ssl->
version>>8);
1019 buf[2]=(
unsigned char)(ssl->
version);
1036 unsigned char dtlsseq[8],*
p=dtlsseq;
1039 memcpy (p,&seq[2],6);
1054 {
unsigned int z;
for (z=0; z<md_size; z++) printf(
"%02X ",mac_sec[z]); printf(
"\n"); }
1056 {
int z;
for (z=0; z<8; z++) printf(
"%02X ",seq[z]); printf(
"\n"); }
1058 {
int z;
for (z=0; z<5; z++) printf(
"%02X ",buf[z]); printf(
"\n"); }
1060 {
unsigned int z;
for (z=0; z<rec->
length; z++) printf(
"%02X ",buf[z]); printf(
"\n"); }
1065 for (i=7; i>=0; i--)
1068 if (seq[i] != 0)
break;
1073 {
unsigned int z;
for (z=0; z<md_size; z++) printf(
"%02X ",md[z]); printf(
"\n"); }
1082 const void *co = NULL, *so = NULL;
1083 int col = 0, sol = 0;
1087 printf (
"tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len);
1090 #ifdef TLSEXT_TYPE_opaque_prf_input
1111 fprintf(stderr,
"Premaster Secret:\n");
1113 fprintf(stderr,
"Client Random:\n");
1115 fprintf(stderr,
"Server Random:\n");
1117 fprintf(stderr,
"Master Secret:\n");
1122 printf (
"tls1_generate_master_secret() complete\n");
1128 const char *label,
size_t llen,
const unsigned char *context,
1129 size_t contextlen,
int use_context)
1131 unsigned char *buff;
1132 unsigned char *val = NULL;
1133 size_t vallen, currentvalpos;
1137 printf (
"tls1_export_keying_material(%p,%p,%d,%s,%d,%p,%d)\n", s, out, olen, label, llen,
p, plen);
1141 if (buff == NULL)
goto err2;
1151 vallen += 2 + contextlen;
1155 if (val == NULL)
goto err2;
1157 memcpy(val + currentvalpos, (
unsigned char *) label, llen);
1158 currentvalpos += llen;
1166 val[currentvalpos] = (contextlen >> 8) & 0xff;
1168 val[currentvalpos] = contextlen & 0xff;
1170 if ((contextlen > 0) || (context != NULL))
1172 memcpy(val + currentvalpos, context, contextlen);
1200 printf (
"tls1_export_keying_material() complete\n");
1251 case DTLS1_AD_MISSING_HANDSHAKE_MESSAGE:
return
1252 (DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);
1254 default:
return(-1);