Definition in file conversion.h.
Go to the source code of this file.
Functions | |
| int | bin_to_base16 (char *from, int len, char *to) |
| Converts a binary encoded value to its base16 representation. | |
| int | base16_to_bin (char *from, int len, char *to) |
| Converts a hex encoded value to its binary value. | |
| int | bin_to_base64 (char *src, int src_len, char *ptr) |
| Convert a binary string to base64 encoding. | |
| int | base64_to_bin (char *src, int src_len, char *ptr) |
| Convert a string encoded in base64 to binary value. | |
| int bin_to_base16 | ( | char * | from, | |
| int | len, | |||
| char * | to | |||
| ) |
Converts a binary encoded value to its base16 representation.
| from | - buffer containing the input data | |
| len | - the size of from | |
| to | - the output buffer !!! must have at least len*2 allocated memory |
Definition at line 92 of file mark.c.
References hexchars.
00093 { 00094 int i,j; 00095 for(i=0,j=0;i<len;i++,j+=2){ 00096 to[j] = hexchars[(((unsigned char)from[i]) >>4 )&0x0F]; 00097 to[j+1] = hexchars[(((unsigned char)from[i]))&0x0F]; 00098 } 00099 return 2*len; 00100 }
| int base16_to_bin | ( | char * | from, | |
| int | len, | |||
| char * | to | |||
| ) |
Converts a hex encoded value to its binary value.
| from | - buffer containing the input data | |
| len | - the size of from | |
| to | - the output buffer !!! must have at least len/2 allocated memory |
Definition at line 112 of file mark.c.
References HEX_DIGIT.
00113 { 00114 int i,j; 00115 for(i=0,j=0;j<len;i++,j+=2){ 00116 to[i] = (unsigned char) ( HEX_DIGIT(from[j])<<4 | HEX_DIGIT(from[j+1])); 00117 } 00118 return i; 00119 }
| int bin_to_base64 | ( | char * | src, | |
| int | src_len, | |||
| char * | ptr | |||
| ) |
Convert a binary string to base64 encoding.
| src | - the source buffer | |
| src_len | - length of the source buffer | |
| ptr | - the destination buffer - must be allocated to at least src_len/3*4+4 |
Definition at line 205 of file conversion.c.
References base64.
Referenced by new_auth_vector().
00206 { 00207 int i,k; 00208 int triplets,rest; 00209 char *s; 00210 s=ptr; 00211 00212 triplets = src_len/3; 00213 rest = src_len%3; 00214 for(i=0;i<triplets*3;i+=3){ 00215 k = (((unsigned char) src[i])&0xFC)>>2; 00216 *ptr=base64[k];ptr++; 00217 00218 k = (((unsigned char) src[i])&0x03)<<4; 00219 k |=(((unsigned char) src[i+1])&0xF0)>>4; 00220 *ptr=base64[k];ptr++; 00221 00222 k = (((unsigned char) src[i+1])&0x0F)<<2; 00223 k |=(((unsigned char) src[i+2])&0xC0)>>6; 00224 *ptr=base64[k];ptr++; 00225 00226 k = (((unsigned char) src[i+2])&0x3F); 00227 *ptr=base64[k];ptr++; 00228 } 00229 i=triplets*3; 00230 switch(rest){ 00231 case 0: 00232 break; 00233 case 1: 00234 k = (((unsigned char) src[i])&0xFC)>>2; 00235 *ptr=base64[k];ptr++; 00236 00237 k = (((unsigned char) src[i])&0x03)<<4; 00238 *ptr=base64[k];ptr++; 00239 00240 *ptr='=';ptr++; 00241 00242 *ptr='=';ptr++; 00243 break; 00244 case 2: 00245 k = (((unsigned char) src[i])&0xFC)>>2; 00246 *ptr=base64[k];ptr++; 00247 00248 k = (((unsigned char) src[i])&0x03)<<4; 00249 k |=(((unsigned char) src[i+1])&0xF0)>>4; 00250 *ptr=base64[k];ptr++; 00251 00252 k = (((unsigned char) src[i+1])&0x0F)<<2; 00253 *ptr=base64[k];ptr++; 00254 00255 *ptr='=';ptr++; 00256 break; 00257 } 00258 00259 return ptr-s; 00260 }
| int base64_to_bin | ( | char * | from, | |
| int | from_len, | |||
| char * | to | |||
| ) |
Convert a string encoded in base64 to binary value.
| from | - buffer containing the input data | |
| from_len | - the size of from | |
| to | - the output buffer !!! must have at least len*2 allocated memory |
Definition at line 178 of file conversion.c.
References base64_val().
Referenced by S_MAR().
00179 { 00180 int i,j,x1,x2,x3,x4; 00181 00182 for(i=0,j=0;i<from_len;i+=4){ 00183 x1=base64_val(from[i]); 00184 x2=base64_val(from[i+1]); 00185 x3=base64_val(from[i+2]); 00186 x4=base64_val(from[i+3]); 00187 to[j++]=(x1<<2) | ((x2 & 0x30)>>4); 00188 if (x3==-1) break; 00189 to[j++]=((x2 & 0x0F)<<4) | ((x3 & 0x3C)>>2); 00190 if (x4==-1) break; 00191 to[j++]=((x3 & 0x03)<<6) | (x4 & 0x3F); 00192 } 00193 return j; 00194 }
1.5.2