| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/rc2/rc2_cbc.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | - | ||||||||||||
| 3 | RC2_KEY *ks, unsigned char *iv, int encrypt) | - | ||||||||||||
| 4 | { | - | ||||||||||||
| 5 | unsigned long tin0,tin1; | - | ||||||||||||
| 6 | unsigned long tout0,tout1,xor0,xor1; | - | ||||||||||||
| 7 | long l=length; | - | ||||||||||||
| 8 | unsigned long tin[2]; | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | if (encrypt
| 6-12 | ||||||||||||
| 11 | { | - | ||||||||||||
| 12 | (tout0 =((unsigned long)(*((iv)++))) , tout0|=((unsigned long)(*((iv)++)))<< 8L, tout0|=((unsigned long)(*((iv)++)))<<16L, tout0|=((unsigned long)(*((iv)++)))<<24L); | - | ||||||||||||
| 13 | (tout1 =((unsigned long)(*((iv)++))) , tout1|=((unsigned long)(*((iv)++)))<< 8L, tout1|=((unsigned long)(*((iv)++)))<<16L, tout1|=((unsigned long)(*((iv)++)))<<24L); | - | ||||||||||||
| 14 | iv-=8; | - | ||||||||||||
| 15 | for (l-=8; l>=0
| 12-672 | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | (tin0 =((unsigned long)(*((in)++))) , tin0|=((unsigned long)(*((in)++)))<< 8L, tin0|=((unsigned long)(*((in)++)))<<16L, tin0|=((unsigned long)(*((in)++)))<<24L); | - | ||||||||||||
| 18 | (tin1 =((unsigned long)(*((in)++))) , tin1|=((unsigned long)(*((in)++)))<< 8L, tin1|=((unsigned long)(*((in)++)))<<16L, tin1|=((unsigned long)(*((in)++)))<<24L); | - | ||||||||||||
| 19 | tin0^=tout0; | - | ||||||||||||
| 20 | tin1^=tout1; | - | ||||||||||||
| 21 | tin[0]=tin0; | - | ||||||||||||
| 22 | tin[1]=tin1; | - | ||||||||||||
| 23 | RC2_encrypt(tin,ks); | - | ||||||||||||
| 24 | tout0=tin[0]; (*((out)++)=(unsigned char)(((tout0) )&0xff), *((out)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((out)++)=(unsigned char)(((tout0)>>16L)&0xff), *((out)++)=(unsigned char)(((tout0)>>24L)&0xff)); | - | ||||||||||||
| 25 | tout1=tin[1]; (*((out)++)=(unsigned char)(((tout1) )&0xff), *((out)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((out)++)=(unsigned char)(((tout1)>>16L)&0xff), *((out)++)=(unsigned char)(((tout1)>>24L)&0xff)); | - | ||||||||||||
| 26 | } executed 672 times by 1 test: end of blockExecuted by:
| 672 | ||||||||||||
| 27 | if (l != -8
| 0-12 | ||||||||||||
| 28 | { | - | ||||||||||||
| 29 | { in+=l+8; tin0=tin1=0; switch (l+8) { case never executed: 8:case 8:never executed: tin1 =((unsigned long)(*(--(in))))<<24L; casecase 8:never executed: 7:case 7:never executed: case 7:code before this statement never executed: tin1|=((unsigned long)(*(--(in))))<<16L; casecase 7:never executed: 6:case 6:never executed: case 6:code before this statement never executed: tin1|=((unsigned long)(*(--(in))))<< 8L; casecase 6:never executed: 5:case 5:never executed: case 5:code before this statement never executed: tin1|=((unsigned long)(*(--(in)))); casecase 5:never executed: 4:case 4:never executed: case 4:code before this statement never executed: tin0 =((unsigned long)(*(--(in))))<<24L; casecase 4:never executed: 3:case 3:never executed: case 3:code before this statement never executed: tin0|=((unsigned long)(*(--(in))))<<16L; casecase 3:never executed: 2:case 2:never executed: case 2:code before this statement never executed: tin0|=((unsigned long)(*(--(in))))<< 8L; casecase 2:never executed: 1:case 1:never executed: case 1:code before this statement never executed: tin0|=((unsigned long)(*(--(in)))); }case 1:never executed: };end of block | 0 | ||||||||||||
| 30 | tin0^=tout0; | - | ||||||||||||
| 31 | tin1^=tout1; | - | ||||||||||||
| 32 | tin[0]=tin0; | - | ||||||||||||
| 33 | tin[1]=tin1; | - | ||||||||||||
| 34 | RC2_encrypt(tin,ks); | - | ||||||||||||
| 35 | tout0=tin[0]; (*((out)++)=(unsigned char)(((tout0) )&0xff), *((out)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((out)++)=(unsigned char)(((tout0)>>16L)&0xff), *((out)++)=(unsigned char)(((tout0)>>24L)&0xff)); | - | ||||||||||||
| 36 | tout1=tin[1]; (*((out)++)=(unsigned char)(((tout1) )&0xff), *((out)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((out)++)=(unsigned char)(((tout1)>>16L)&0xff), *((out)++)=(unsigned char)(((tout1)>>24L)&0xff)); | - | ||||||||||||
| 37 | } never executed: end of block | 0 | ||||||||||||
| 38 | (*((iv)++)=(unsigned char)(((tout0) )&0xff), *((iv)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((iv)++)=(unsigned char)(((tout0)>>16L)&0xff), *((iv)++)=(unsigned char)(((tout0)>>24L)&0xff)); | - | ||||||||||||
| 39 | (*((iv)++)=(unsigned char)(((tout1) )&0xff), *((iv)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((iv)++)=(unsigned char)(((tout1)>>16L)&0xff), *((iv)++)=(unsigned char)(((tout1)>>24L)&0xff)); | - | ||||||||||||
| 40 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 41 | else | - | ||||||||||||
| 42 | { | - | ||||||||||||
| 43 | (xor0 =((unsigned long)(*((iv)++))) , xor0|=((unsigned long)(*((iv)++)))<< 8L, xor0|=((unsigned long)(*((iv)++)))<<16L, xor0|=((unsigned long)(*((iv)++)))<<24L); | - | ||||||||||||
| 44 | (xor1 =((unsigned long)(*((iv)++))) , xor1|=((unsigned long)(*((iv)++)))<< 8L, xor1|=((unsigned long)(*((iv)++)))<<16L, xor1|=((unsigned long)(*((iv)++)))<<24L); | - | ||||||||||||
| 45 | iv-=8; | - | ||||||||||||
| 46 | for (l-=8; l>=0
| 6-672 | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | (tin0 =((unsigned long)(*((in)++))) , tin0|=((unsigned long)(*((in)++)))<< 8L, tin0|=((unsigned long)(*((in)++)))<<16L, tin0|=((unsigned long)(*((in)++)))<<24L); tin[0]=tin0; | - | ||||||||||||
| 49 | (tin1 =((unsigned long)(*((in)++))) , tin1|=((unsigned long)(*((in)++)))<< 8L, tin1|=((unsigned long)(*((in)++)))<<16L, tin1|=((unsigned long)(*((in)++)))<<24L); tin[1]=tin1; | - | ||||||||||||
| 50 | RC2_decrypt(tin,ks); | - | ||||||||||||
| 51 | tout0=tin[0]^xor0; | - | ||||||||||||
| 52 | tout1=tin[1]^xor1; | - | ||||||||||||
| 53 | (*((out)++)=(unsigned char)(((tout0) )&0xff), *((out)++)=(unsigned char)(((tout0)>> 8L)&0xff), *((out)++)=(unsigned char)(((tout0)>>16L)&0xff), *((out)++)=(unsigned char)(((tout0)>>24L)&0xff)); | - | ||||||||||||
| 54 | (*((out)++)=(unsigned char)(((tout1) )&0xff), *((out)++)=(unsigned char)(((tout1)>> 8L)&0xff), *((out)++)=(unsigned char)(((tout1)>>16L)&0xff), *((out)++)=(unsigned char)(((tout1)>>24L)&0xff)); | - | ||||||||||||
| 55 | xor0=tin0; | - | ||||||||||||
| 56 | xor1=tin1; | - | ||||||||||||
| 57 | } executed 672 times by 1 test: end of blockExecuted by:
| 672 | ||||||||||||
| 58 | if (l != -8
| 0-6 | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | (tin0 =((unsigned long)(*((in)++))) , tin0|=((unsigned long)(*((in)++)))<< 8L, tin0|=((unsigned long)(*((in)++)))<<16L, tin0|=((unsigned long)(*((in)++)))<<24L); tin[0]=tin0; | - | ||||||||||||
| 61 | (tin1 =((unsigned long)(*((in)++))) , tin1|=((unsigned long)(*((in)++)))<< 8L, tin1|=((unsigned long)(*((in)++)))<<16L, tin1|=((unsigned long)(*((in)++)))<<24L); tin[1]=tin1; | - | ||||||||||||
| 62 | RC2_decrypt(tin,ks); | - | ||||||||||||
| 63 | tout0=tin[0]^xor0; | - | ||||||||||||
| 64 | tout1=tin[1]^xor1; | - | ||||||||||||
| 65 | { out+=l+8; switch (l+8) { case never executed: 8:case 8:never executed: *(--(out))=(unsigned char)(((tout1)>>24L)&0xff); casecase 8:never executed: 7:case 7:never executed: case 7:code before this statement never executed: *(--(out))=(unsigned char)(((tout1)>>16L)&0xff); casecase 7:never executed: 6:case 6:never executed: case 6:code before this statement never executed: *(--(out))=(unsigned char)(((tout1)>> 8L)&0xff); casecase 6:never executed: 5:case 5:never executed: case 5:code before this statement never executed: *(--(out))=(unsigned char)(((tout1) )&0xff); casecase 5:never executed: 4:case 4:never executed: case 4:code before this statement never executed: *(--(out))=(unsigned char)(((tout0)>>24L)&0xff); casecase 4:never executed: 3:case 3:never executed: case 3:code before this statement never executed: *(--(out))=(unsigned char)(((tout0)>>16L)&0xff); casecase 3:never executed: 2:case 2:never executed: case 2:code before this statement never executed: *(--(out))=(unsigned char)(((tout0)>> 8L)&0xff); casecase 2:never executed: 1:case 1:never executed: case 1:code before this statement never executed: *(--(out))=(unsigned char)(((tout0) )&0xff); }case 1:never executed: };end of block | 0 | ||||||||||||
| 66 | xor0=tin0; | - | ||||||||||||
| 67 | xor1=tin1; | - | ||||||||||||
| 68 | } never executed: end of block | 0 | ||||||||||||
| 69 | (*((iv)++)=(unsigned char)(((xor0) )&0xff), *((iv)++)=(unsigned char)(((xor0)>> 8L)&0xff), *((iv)++)=(unsigned char)(((xor0)>>16L)&0xff), *((iv)++)=(unsigned char)(((xor0)>>24L)&0xff)); | - | ||||||||||||
| 70 | (*((iv)++)=(unsigned char)(((xor1) )&0xff), *((iv)++)=(unsigned char)(((xor1)>> 8L)&0xff), *((iv)++)=(unsigned char)(((xor1)>>16L)&0xff), *((iv)++)=(unsigned char)(((xor1)>>24L)&0xff)); | - | ||||||||||||
| 71 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 72 | tin0=tin1=tout0=tout1=xor0=xor1=0; | - | ||||||||||||
| 73 | tin[0]=tin[1]=0; | - | ||||||||||||
| 74 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 75 | - | |||||||||||||
| 76 | void RC2_encrypt(unsigned long *d, RC2_KEY *key) | - | ||||||||||||
| 77 | { | - | ||||||||||||
| 78 | int i,n; | - | ||||||||||||
| 79 | unsigned int *p0,*p1; | - | ||||||||||||
| 80 | unsigned int x0,x1,x2,x3,t; | - | ||||||||||||
| 81 | unsigned long l; | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | l=d[0]; | - | ||||||||||||
| 84 | x0=(unsigned int)l&0xffff; | - | ||||||||||||
| 85 | x1=(unsigned int)(l>>16L); | - | ||||||||||||
| 86 | l=d[1]; | - | ||||||||||||
| 87 | x2=(unsigned int)l&0xffff; | - | ||||||||||||
| 88 | x3=(unsigned int)(l>>16L); | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | n=3; | - | ||||||||||||
| 91 | i=5; | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | p0=p1= &(key->data[0]); | - | ||||||||||||
| 94 | for (;;) | - | ||||||||||||
| 95 | { | - | ||||||||||||
| 96 | t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; | - | ||||||||||||
| 97 | x0=(t<<1)|(t>>15); | - | ||||||||||||
| 98 | t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; | - | ||||||||||||
| 99 | x1=(t<<2)|(t>>14); | - | ||||||||||||
| 100 | t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; | - | ||||||||||||
| 101 | x2=(t<<3)|(t>>13); | - | ||||||||||||
| 102 | t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; | - | ||||||||||||
| 103 | x3=(t<<5)|(t>>11); | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | if (--
| 5364-23244 | ||||||||||||
| 106 | { | - | ||||||||||||
| 107 | if (--
executed 1788 times by 2 tests: break;Executed by:
| 1788-3576 | ||||||||||||
| 108 | i=(
| 1788 | ||||||||||||
| 109 | - | |||||||||||||
| 110 | x0+=p1[x3&0x3f]; | - | ||||||||||||
| 111 | x1+=p1[x0&0x3f]; | - | ||||||||||||
| 112 | x2+=p1[x1&0x3f]; | - | ||||||||||||
| 113 | x3+=p1[x2&0x3f]; | - | ||||||||||||
| 114 | } executed 3576 times by 2 tests: end of blockExecuted by:
| 3576 | ||||||||||||
| 115 | } executed 26820 times by 2 tests: end of blockExecuted by:
| 26820 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); | - | ||||||||||||
| 118 | d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); | - | ||||||||||||
| 119 | } executed 1788 times by 2 tests: end of blockExecuted by:
| 1788 | ||||||||||||
| 120 | - | |||||||||||||
| 121 | void RC2_decrypt(unsigned long *d, RC2_KEY *key) | - | ||||||||||||
| 122 | { | - | ||||||||||||
| 123 | int i,n; | - | ||||||||||||
| 124 | unsigned int *p0,*p1; | - | ||||||||||||
| 125 | unsigned int x0,x1,x2,x3,t; | - | ||||||||||||
| 126 | unsigned long l; | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | l=d[0]; | - | ||||||||||||
| 129 | x0=(unsigned int)l&0xffff; | - | ||||||||||||
| 130 | x1=(unsigned int)(l>>16L); | - | ||||||||||||
| 131 | l=d[1]; | - | ||||||||||||
| 132 | x2=(unsigned int)l&0xffff; | - | ||||||||||||
| 133 | x3=(unsigned int)(l>>16L); | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | n=3; | - | ||||||||||||
| 136 | i=5; | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | p0= &(key->data[63]); | - | ||||||||||||
| 139 | p1= &(key->data[0]); | - | ||||||||||||
| 140 | for (;;) | - | ||||||||||||
| 141 | { | - | ||||||||||||
| 142 | t=((x3<<11)|(x3>>5))&0xffff; | - | ||||||||||||
| 143 | x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff; | - | ||||||||||||
| 144 | t=((x2<<13)|(x2>>3))&0xffff; | - | ||||||||||||
| 145 | x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff; | - | ||||||||||||
| 146 | t=((x1<<14)|(x1>>2))&0xffff; | - | ||||||||||||
| 147 | x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff; | - | ||||||||||||
| 148 | t=((x0<<15)|(x0>>1))&0xffff; | - | ||||||||||||
| 149 | x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff; | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | if (--
| 2700-11700 | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | if (--
executed 900 times by 2 tests: break;Executed by:
| 900-1800 | ||||||||||||
| 154 | i=(
| 900 | ||||||||||||
| 155 | - | |||||||||||||
| 156 | x3=(x3-p1[x2&0x3f])&0xffff; | - | ||||||||||||
| 157 | x2=(x2-p1[x1&0x3f])&0xffff; | - | ||||||||||||
| 158 | x1=(x1-p1[x0&0x3f])&0xffff; | - | ||||||||||||
| 159 | x0=(x0-p1[x3&0x3f])&0xffff; | - | ||||||||||||
| 160 | } executed 1800 times by 2 tests: end of blockExecuted by:
| 1800 | ||||||||||||
| 161 | } executed 13500 times by 2 tests: end of blockExecuted by:
| 13500 | ||||||||||||
| 162 | - | |||||||||||||
| 163 | d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); | - | ||||||||||||
| 164 | d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); | - | ||||||||||||
| 165 | } executed 900 times by 2 tests: end of blockExecuted by:
| 900 | ||||||||||||
| Switch to Source code | Preprocessed file |