/* * rotn_encrypt -- * A simple encryption example that passes data through unchanged. */ static int rotn_encrypt(WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) { ROTN_ENCRYPTOR *rotn_encryptor = (ROTN_ENCRYPTOR *)encryptor; uint32_t i; (void)session; /* Unused */ if (dst_len < src_len + CHKSUM_LEN + IV_LEN) return (ENOMEM); /* * !!! Most implementations would verify any needed * checksum and initialize the IV here. */ i = CHKSUM_LEN + IV_LEN; memcpy(&dst[i], &src[0], src_len); /* * Depending on whether we have a secret key or not, * call the common rotate or shift function on the text portion * of the destination buffer. Send in src_len as the length of * the text. */ if (rotn_encryptor->shift_len == 0) do_rotate((char *)dst + i, src_len, rotn_encryptor->rot_N); else do_shift(&dst[i], src_len, rotn_encryptor->shift_forw, rotn_encryptor->shift_len); /* * Checksum the encrypted buffer and add the IV. */ i = 0; make_cksum(&dst[i]); i += CHKSUM_LEN; make_iv(&dst[i]); *result_lenp = dst_len; return (0); }
/* * rotate_encrypt -- * A simple rotate encryption. */ static int rotate_encrypt(WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) { MY_CRYPTO *my_crypto = (MY_CRYPTO *)encryptor; uint32_t i; (void)session; /* Unused */ ++my_crypto->num_calls; if (src == NULL) return (0); if (dst_len < src_len + CHKSUM_LEN + IV_LEN) return (ENOMEM); i = CHKSUM_LEN + IV_LEN; /* * Skip over space reserved for checksum and initialization * vector. Copy text into destination buffer then encrypt * in place. */ memcpy(&dst[i], &src[0], src_len); /* * Call common rotate function on the text portion of the * destination buffer. Send in src_len as the length of * the text. */ do_rotate((char *)dst + i, src_len, my_crypto->rot_N); /* * Checksum the encrypted buffer and add the IV. */ i = 0; make_cksum(&dst[i]); i += CHKSUM_LEN; make_iv(&dst[i]); *result_lenp = dst_len; return (0); }