/* Returned string must be freed when done with it! */ int encrypt_string(const char *key, const char *str, char *dest, int len) { BF_KEY bf_key; if ( !key || !key[0] ) return 0; BF_set_key(&bf_key, strlen(key), (const unsigned char *)key); while( len > 0 ) { const size_t blocksize = len < 8 ? len : BF_BLOCK; unsigned char block[BF_BLOCK] = {0}; /* pad with zero */ uint32_t v; size_t i; memcpy(block, str, blocksize); BF_ecb_encrypt(block, block, &bf_key, BF_ENCRYPT); for(v = load32_be(block + 4), i = 0; i < 6; ++i) { *dest++ = B64[v&0x3f]; v >>= 6; } for(v = load32_be(block + 0), i = 0; i < 6; ++i) { *dest++ = B64[v&0x3f]; v >>= 6; } len -= blocksize; str += blocksize; } *dest++ = 0; return 1; }
void Hacl_Hash_Lib_LoadStore_uint32s_from_be_bytes(uint32_t *output, uint8_t *input, uint32_t len) { for (uint32_t i = (uint32_t )0; i < len; i = i + (uint32_t )1) { uint8_t *x0 = input + (uint32_t )4 * i; uint32_t inputi = load32_be(x0); output[i] = inputi; } }