static int fdecode(FILE *in, FILE *out) { off_t buflen; off_t count; char *decbuf = NULL; char *ptr = NULL; off_t pos; pos = 0; while(!feof(in)) { count = fread(buf, 1, sizeof(buf), in); if ( count <= 0 ) return -1; ptr = realloc(decbuf, count+pos); if ( !ptr ) die(ENOMEM, "Out of memory in fdecode"); decbuf = ptr; memcpy(decbuf+pos, buf, count); pos += count; } ptr = malloc(base32decsize(pos)); buflen = base32dec(ptr, pos, decbuf); // buflen is exact fwrite(ptr, 1, buflen, out); return 0; }
vector<string> decrypt (vector<string> cipher, string keystr, primenc_et contprimenc, contenc_et contsecenc) { byte primdecarr[CIPHERLEN*20+1]; uint32_t i; vector<string> decvec; for(i=0;i<cipher.size();i++){ if(NO_PRIMENC == contprimenc){ nodec(primdecarr, cipher[i]); }else if(BASE64 == contprimenc){ base64dec(primdecarr, cipher[i]); }else if(BASE32 == contprimenc){ base32dec(primdecarr, cipher[i]); }else if(BASE16 == contprimenc){ base16dec(primdecarr, cipher[i]); }else{ throw contprimenc; cout << "This primary encoding is not supported yet." << endl; } if(NO_CONTENC == contsecenc){ decvec.push_back(nocrypt(primdecarr)); }else if(AES_128 == contsecenc){ decvec.push_back(AESdec(primdecarr, keystr)); }else{ throw contsecenc; cout << "This secondary encoding is not supported yet." << endl; } } return decvec; }
string b32AESdec(string b32cipher, string keystr) { byte b32decarr[CIPHERLEN*8/5*4+1]; base32dec(b32decarr, b32cipher); return AESdec(b32decarr, keystr); }
void base32dec(byte* dec, string base32str) { std::transform(base32str.begin(), base32str.end(), base32str.begin(), ::toupper); base32dec(dec, (byte*) base32str.c_str(), base32str.size()); }