Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261517AbVCGUwz (ORCPT ); Mon, 7 Mar 2005 15:52:55 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261656AbVCGUvy (ORCPT ); Mon, 7 Mar 2005 15:51:54 -0500 Received: from mailer.campus.mipt.ru ([194.85.82.4]:2738 "EHLO mailer.campus.mipt.ru") by vger.kernel.org with ESMTP id S261801AbVCGUNa convert rfc822-to-8bit (ORCPT ); Mon, 7 Mar 2005 15:13:30 -0500 Cc: Fruhwirth Clemens , Herbert Xu , cryptoapi@lists.logix.cz, James Morris , David Miller , Andrew Morton , Evgeniy Polyakov Subject: [??/many] iok.c - simple example of the userspace acrypto usage [IOCTL] In-Reply-To: <1110227853899@2ka.mipt.ru> X-Mailer: gregkh_patchbomb Date: Mon, 7 Mar 2005 23:37:33 +0300 Message-Id: <1110227853606@2ka.mipt.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Reply-To: Evgeniy Polyakov To: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 7BIT From: Evgeniy Polyakov X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.7.5 (mailer.campus.mipt.ru [194.85.82.4]); Mon, 07 Mar 2005 23:11:25 +0300 (MSK) Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3208 Lines: 175 #include #include #include #include #include #include #include #include #include #include #include "crypto_user.h" #include "crypto_user_ioctl.h" #include "crypto_def.h" #define ulog(f, a...) fprintf(stderr, f, ##a) int session_add(int fd, void *ptr) { int err; err = ioctl(fd, CRYPTO_SESSION_ADD, ptr); if (err == -1) { ulog("Failed to do CRYPTO_SESSION_ADD: %s [%d].\n", strerror(errno), errno); return -1; } ulog("CRYPTO_SESSION_ADD finished.\n"); return 0; } int session_alloc(int fd, struct crypto_user_ioctl *io) { int err; err = ioctl(fd, CRYPTO_SESSION_ALLOC, io); if (err == -1) { ulog("Failed to do CRYPTO_SESSION_ALLOC: %s [%d].\n", strerror(errno), errno); return -1; } ulog("CRYPTO_SESSION_ALLOC finished.\n"); return 0; } int fill_data(int fd, unsigned short size, unsigned short type, void *ptr) { int err; struct crypto_user_data *d; void *data; data = malloc(size + sizeof(*d)); if (!data) { ulog("Failed to allocate %d bytes for CRYPTO_FILL_DATA[%u.%x].\n", size + sizeof(*d), size, type); return -ENOMEM; } d = (struct crypto_user_data *)data; d->data_size = size; d->data_type = type; memcpy(d+1, ptr, size); err = ioctl(fd, CRYPTO_FILL_DATA, d); if (err == -1) { ulog("Failed to do CRYPTO_FILL_DATA[%u.%x]: %s [%d].\n", size, type, strerror(errno), errno); free(data); return -1; } free(data); ulog("CRYPTO_FILL_DATA[%u.%x] finished.\n", size, type); return 0; } static void dump_data(unsigned char *ptr, int size) { int i; ulog("IOK DATA: "); for (i=0; i