7 #include <mxhw_crypto_io.h>
9 #define MXCIPHER_DEV_NODE "/dev/mxcrypto" /* device node */
12 mxcrypto_uio_register(u_int algo
, u_int mode
, u_char
*keys
, u_int bits
, int type
)
17 DBG("mxhw_userio: mxcrypto_uio_register %d %d %d\n", 11,algo
,mode
);
19 /* open a new context */
20 if ( (fd
= open(MXCIPHER_DEV_NODE
, O_RDWR
, 0)) < 0 )
23 /* register this context with parameters */
24 info
.type
= (type
)? 1:0;
28 memcpy(info
.keys
, keys
, MAX_MXCIPHER_LEN_KEYS
);
29 if ( (i
= ioctl(fd
, IOCTLSET_MXCIPHER_INFO
, &info
)) < 0 )
34 DBG("mxhw_userio: mxcrypto_uio_register %d\n", 99);
39 mxcrypto_uio_perform(int ctrl
, const u_char
*input
, u_char
*output
, u_long length
,
40 u_char
*ivec
, u_int ilen
)
43 u_char data
[MAX_CIPHER_PACKET
], *ibuf
, *obuf
;
45 DBG("mxhw_userio: mxcrypto_uio_perform %d %ld %d\n", 11, length
, ilen
);
49 if (ivec
!=NULL
&& ilen
>0)
51 if ((length
+ilen
)>MAX_CIPHER_PACKET
)
54 memcpy(ibuf
, input
, length
);
55 memcpy(ibuf
+length
, ivec
, ilen
);
60 ibuf
= (u_char
*) input
;
63 DBG("mxhw_userio: mxcrypto_uio_perform %d %ld %d\n", 22, length
, ilen
);
64 /* send request to the engine and wait for response */
65 if ((n
=write(ctrl
, ibuf
, length
)) < 0)
67 DBG("error: write %d\n", n
);
70 DBG("mxhw_userio: mxcrypto_uio_perform %d %ld %d\n", 33, length
, ilen
);
71 if ((n
=read(ctrl
, obuf
, length
)) < 0)
73 DBG("error: read %d\n", n
);
76 DBG("mxhw_userio: mxcrypto_uio_perform %d %ld %d\n", 44, length
, ilen
);
77 if (ivec
!=NULL
&& ilen
>0)
80 memcpy(output
, obuf
, length
);
81 memcpy(ivec
, obuf
+length
, ilen
);
83 DBG("mxhw_userio: mxcrypto_uio_perform %d\n", 99);
88 mxcrypto_uio_close(int fd
)
92 if ( ioctl(fd
, 99, &size
) < 0 )
100 mxcrypto_uio_write(int ctxId
, const u_char
*input
, u_long len
, u_char
*ivec
, int ilen
)
104 /* send request to the engine and wait for response */
105 if ((n
=write(ctxId
, input
, len
+ilen
)) < 0)
106 DBG("error: write/read %d\n", n
);
111 mxcrypto_uio_read(int ctxId
, u_char
*output
, u_long len
, u_char
*ivec
, int ilen
)
115 /* send request to the engine and wait for response */
116 if ((n
=read(ctxId
, output
, len
+ilen
)) < 0)
117 DBG("error: write/read %d\n", n
);
122 mxcrypto_uio_queue(int ctxId
)
126 if (ioctl(ctxId
, 100, &n
)<0)