Please look to patch description.

normally OpenSSL API use looks like:

http://www.openssl.org/docs/crypto/sha.html#


SHA1_Init()
SHA1_Update()
...
..
SHA1_Update()
SHA1_Final()


This is how openssl like api looks like


int cryptodev_open(CRYPTO_CTX *ctx)
{
        /* Open the crypto device */
        ctx->fd = open("/dev/crypto", O_RDWR, 0);
        if (ctx->fd < 0) {
                perror("open(/dev/crypto)");
                return 1;
        }

        /* Clone file descriptor */
        if (ioctl(ctx->fd, CRIOGET, &ctx->cfd)) {
                perror("ioctl(CRIOGET)");
                return 1;
        }

        /* Set close-on-exec (not really neede here) */
        if (fcntl(ctx->cfd, F_SETFD, 1) == -1) {
                perror("fcntl(F_SETFD)");
                return 1;
        }
        
        return 0;
}

int cryptodev_close(CRYPTO_CTX *ctx)
{
        /* Finish crypto session */
        if (ioctl(ctx->cfd, CIOCFSESSION, &ctx->sess.ses)) {
                perror("ioctl(CIOCFSESSION)");
                return 1;
        }

        /* Close cloned descriptor */
        if (close(ctx->cfd)) {
                perror("close(cfd)");
                return 1;
        }

        /* Close the original descriptor */
        if (close(ctx->fd)) {
                perror("close(fd)");
                return 1;
        }
        return 0;
}

int HASH_Init(SHA_CTX *ctx, int mac)
{
        if (cryptodev_open(ctx))
                return 0;

        /* SHA1 plain test */
        memset(&ctx->sess, 0, sizeof(ctx->sess));
        
        ctx->sess.cipher = 0;
        ctx->sess.mac = mac;
        if (ioctl(ctx->cfd, CIOCGSESSION, &ctx->sess)) {
                perror("ioctl(CIOCGSESSION)");
                return 0;
        }

        return 1;
}

int HASH_Update(SHA_CTX *ctx, const void *data, unsigned long len)
{
        struct crypt_op cryp;
        
        cryp.ses = ctx->sess.ses;
        cryp.len = len;
        cryp.src = (void *)data;
        cryp.mac = ctx->mac;
        cryp.op = COP_ENCRYPT;
        cryp.flags = COP_FLAG_UPDATE;

        if (ioctl(ctx->cfd, CIOCCRYPT, &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 0;
        }

        return 1;
}


Dmitry Kasatkin (1):
  multi-update support for hash calculation

 cryptodev.h      |    1 +
 cryptodev_main.c |   15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)


_______________________________________________
Cryptodev-linux-devel mailing list
Cryptodev-linux-devel@gna.org
https://mail.gna.org/listinfo/cryptodev-linux-devel

Reply via email to