On 09/07/2008 10:42 PM, [EMAIL PROTECTED] wrote:
+static unsigned char *encrypt_block(abts_case *tc, apr_pool_t *pool,
+ const apr_crypto_driver_t *driver, const apr_crypto_t *f,
+ const apr_crypto_key_t *key, const unsigned char *in,
+ const apr_size_t inlen, unsigned char **cipherText,
+ apr_size_t *cipherTextLen, const unsigned char **iv,
+ apr_size_t *blockSize, const char *description) {
+
+ apr_crypto_block_t *block = NULL;
+ apr_size_t len = 0;
+ apr_status_t rv;
+
+ if (!driver || !f || !key || !in) {
+ return NULL;
+ }
+
+ /* init the encryption */
+ rv = apr_crypto_block_encrypt_init(driver, pool, f, key, iv, &block,
+ blockSize);
+ if (APR_ENOTIMPL == rv) {
+ ABTS_NOT_IMPL(tc, "apr_crypto_block_encrypt_init returned
APR_ENOTIMPL");
+ } else {
+ if (APR_SUCCESS != rv) {
+ fprintf(stderr, "encrypt_init: %s %s native error %d: %s (%s)\n",
+ description, apr_crypto_driver_name(driver), f->result->rc,
+ f->result->reason ? f->result->reason : "",
+ f->result->msg ? f->result->msg : "");
+ }
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_init returned APR_ENOKEY",
rv != APR_ENOKEY);
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_init returned APR_ENOIV", rv
!= APR_ENOIV);
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_init returned APR_EKEYTYPE",
rv != APR_EKEYTYPE);
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_init returned
APR_EKEYLENGTH", rv != APR_EKEYLENGTH);
+ ABTS_ASSERT(tc, "failed to apr_crypto_block_encrypt_init", rv ==
APR_SUCCESS);
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_init returned NULL context",
block != NULL);
+ }
+ if (!block || rv) {
+ return NULL;
+ }
+
+ /* encrypt the block */
+ rv = apr_crypto_block_encrypt(driver, block, cipherText + len,
What is the purpose of cipherText + len?
len is always 0 and cipherText is char ** and not char *.
+ cipherTextLen, in, inlen);
+ if (APR_SUCCESS != rv) {
+ fprintf(stderr, "encrypt: %s %s native error %d: %s (%s)\n",
+ description, apr_crypto_driver_name(driver), f->result->rc,
+ f->result->reason ? f->result->reason : "",
+ f->result->msg ? f->result->msg : "");
+ }
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt returned APR_ECRYPT", rv !=
APR_ECRYPT);
+ ABTS_ASSERT(tc, "failed to apr_crypto_block_encrypt", rv == APR_SUCCESS);
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt failed to allocate buffer",
*cipherText != NULL);
+ if (rv) {
+ return NULL;
+ }
+
+ /* finalise the encryption */
+ rv = apr_crypto_block_encrypt_finish(driver, block, *cipherText
+ + *cipherTextLen, &len);
+ if (APR_SUCCESS != rv) {
+ fprintf(stderr, "encrypt_finish: %s %s native error %d: %s (%s)\n",
+ description, apr_crypto_driver_name(driver), f->result->rc,
+ f->result->reason ? f->result->reason : "",
+ f->result->msg ? f->result->msg : "");
+ }
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_finish returned APR_ECRYPT", rv
!= APR_ECRYPT);
+ ABTS_ASSERT(tc, "apr_crypto_block_encrypt_finish returned APR_EPADDING",
rv != APR_EPADDING);
+ ABTS_ASSERT(tc, "failed to apr_crypto_block_encrypt_finish", rv ==
APR_SUCCESS);
+ *cipherTextLen += len;
+ apr_crypto_block_cleanup(driver, block);
+ if (rv) {
+ return NULL;
+ }
+
+ return *cipherText;
+
+}
+
+/**
+ * Simple test of OpenSSL block crypt.
+ */
+static void test_crypto_block_openssl(abts_case *tc, void *data) {
+ apr_pool_t *pool = NULL;
+ const apr_crypto_driver_t *drivers[] = { NULL, NULL };
+
+ const unsigned char *in = (const unsigned char *) ALIGNED_STRING;
+ apr_size_t inlen = sizeof(ALIGNED_STRING);
+
+ apr_pool_create(&pool, NULL);
Why do we need a fresh pool for every test? Why can't we create it once for all
test?
Regards
RĂ¼diger