| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/des/enc_writ.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | int DES_enc_write(int fd, const void *_buf, int len, | - | ||||||||||||
| 4 | DES_key_schedule *sched, DES_cblock *iv) | - | ||||||||||||
| 5 | { | - | ||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | const unsigned char *buf=_buf; | - | ||||||||||||
| 11 | long rnum; | - | ||||||||||||
| 12 | int i,j,k,outnum; | - | ||||||||||||
| 13 | static unsigned char *outbuf= | - | ||||||||||||
| 14 | ((void *)0) | - | ||||||||||||
| 15 | ; | - | ||||||||||||
| 16 | unsigned char shortbuf[8]; | - | ||||||||||||
| 17 | unsigned char *p; | - | ||||||||||||
| 18 | const unsigned char *cp; | - | ||||||||||||
| 19 | static int start=1; | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | if (outbuf ==
| 0 | ||||||||||||
| 22 | ((void *)0)
| 0 | ||||||||||||
| 23 | ) | - | ||||||||||||
| 24 | { | - | ||||||||||||
| 25 | outbuf=malloc(((1024*16)+4)+4); | - | ||||||||||||
| 26 | if (outbuf ==
| 0 | ||||||||||||
| 27 | ((void *)0)
| 0 | ||||||||||||
| 28 | ) return never executed: (-1);return(-1);never executed: return(-1); | 0 | ||||||||||||
| 29 | } never executed: end of block | 0 | ||||||||||||
| 30 | - | |||||||||||||
| 31 | - | |||||||||||||
| 32 | if (start
| 0 | ||||||||||||
| 33 | { | - | ||||||||||||
| 34 | start=0; | - | ||||||||||||
| 35 | } never executed: end of block | 0 | ||||||||||||
| 36 | - | |||||||||||||
| 37 | - | |||||||||||||
| 38 | if (len > (1024*16)
| 0 | ||||||||||||
| 39 | { | - | ||||||||||||
| 40 | j=0; | - | ||||||||||||
| 41 | for (i=0; i<len
| 0 | ||||||||||||
| 42 | { | - | ||||||||||||
| 43 | k=DES_enc_write(fd,&(buf[i]), | - | ||||||||||||
| 44 | ((len-i) > (1024*16))?(1024*16):(len-i),sched,iv); | - | ||||||||||||
| 45 | if (k < 0
| 0 | ||||||||||||
| 46 | return never executed: (k);return(k);never executed: return(k); | 0 | ||||||||||||
| 47 | else | - | ||||||||||||
| 48 | j+=k; never executed: j+=k; | 0 | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | return never executed: (j);return(j);never executed: return(j); | 0 | ||||||||||||
| 51 | } | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | - | |||||||||||||
| 54 | p=outbuf; | - | ||||||||||||
| 55 | (*((p)++)=(unsigned char)(((len)>>24L)&0xff), *((p)++)=(unsigned char)(((len)>>16L)&0xff), *((p)++)=(unsigned char)(((len)>> 8L)&0xff), *((p)++)=(unsigned char)(((len) )&0xff)); | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | - | |||||||||||||
| 58 | if (len < 8
| 0 | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | cp=shortbuf; | - | ||||||||||||
| 61 | memcpy(shortbuf,buf,len); | - | ||||||||||||
| 62 | arc4random_buf(shortbuf+len, 8-len); | - | ||||||||||||
| 63 | rnum=8; | - | ||||||||||||
| 64 | } never executed: end of block | 0 | ||||||||||||
| 65 | else | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | cp=buf; | - | ||||||||||||
| 68 | rnum=((len+7)/8*8); | - | ||||||||||||
| 69 | } never executed: end of block | 0 | ||||||||||||
| 70 | - | |||||||||||||
| 71 | if (DES_rw_mode & 1
| 0 | ||||||||||||
| 72 | DES_pcbc_encrypt(cp,&(outbuf[4]),(len<8)?8:len,sched,iv, never executed: DES_pcbc_encrypt(cp,&(outbuf[4]),(len<8)?8:len,sched,iv, 1); | 0 | ||||||||||||
| 73 | 1); never executed: DES_pcbc_encrypt(cp,&(outbuf[4]),(len<8)?8:len,sched,iv, 1); | 0 | ||||||||||||
| 74 | else | - | ||||||||||||
| 75 | DES_cbc_encrypt(cp,&(outbuf[4]),(len<8)?8:len,sched,iv, never executed: DES_cbc_encrypt(cp,&(outbuf[4]),(len<8)?8:len,sched,iv, 1); | 0 | ||||||||||||
| 76 | 1); never executed: DES_cbc_encrypt(cp,&(outbuf[4]),(len<8)?8:len,sched,iv, 1); | 0 | ||||||||||||
| 77 | - | |||||||||||||
| 78 | - | |||||||||||||
| 79 | outnum=rnum+4; | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | for (j=0; j<outnum
| 0 | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | - | |||||||||||||
| 85 | i=write(fd,(void *)&(outbuf[j]),outnum-j); | - | ||||||||||||
| 86 | if (i == -1
| 0 | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | if ( | - | ||||||||||||
| 90 | (*
| 0 | ||||||||||||
| 91 | ==
| 0 | ||||||||||||
| 92 | 4
| 0 | ||||||||||||
| 93 | ) | - | ||||||||||||
| 94 | i=0; never executed: i=0; | 0 | ||||||||||||
| 95 | else | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | - | |||||||||||||
| 98 | - | |||||||||||||
| 99 | return never executed: (-1);return(-1);never executed: return(-1); | 0 | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | } never executed: end of block | 0 | ||||||||||||
| 102 | - | |||||||||||||
| 103 | return never executed: (len);return(len);never executed: return(len); | 0 | ||||||||||||
| 104 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |