Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* tentative include files */
- #include <sys/param.h>
- #include <sys/module.h>
- #include <sys/kernel.h>
- #include <sys/systm.h>
- #include <sys/malloc.h>
- #include <sys/lock.h>
- #include <sys/mutex.h>
- #include <opencrypto/cryptodev.h>
- struct mtx ds_lock;
- static int
- hmac_cmplted_cb(struct cryptop *crp)
- {
- uprintf("hmac_cmplted_cb\n");
- int error;
- error = crp->crp_etype;
- uprintf("Error:CB:%d\n", error);
- if (error == EAGAIN)
- {
- uprintf("EAGAIN!\n");
- error = crypto_dispatch(crp);
- }
- if (error || (crp->crp_flags & CRYPTO_F_DONE))
- {
- uprintf("Wakeup!\n");
- wakeup(crp);
- }
- return (0);
- }
- static void hmac_test()
- {
- uprintf("Entering HMAC_test function\n");
- crypto_session_t ds_session;
- struct cryptoini cri[1];
- char block_to_encrypt[24] = "ABCDABCD12341234ABCDABCD";
- char key[11] = "neverGiveUp";
- int error;
- bzero(cri, sizeof(cri));
- //bzero(key, sizeof(key));
- cri[0].cri_alg = CRYPTO_SHA2_256_HMAC;
- cri[0].cri_klen = 11;
- cri[0].cri_mlen = 0;
- cri[0].cri_key = key;
- cri[0].cri_next = NULL;
- crypto_newsession(&ds_session, cri,
- CRYPTOCAP_F_SOFTWARE);
- // CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE);
- uprintf("%p\n", (caddr_t)ds_session);
- //Do the HMAC computation here.
- struct cryptop *crp;
- struct cryptodesc *crd;
- crp = crypto_getreq(1); //Allocating crp with one crp_desc.
- crd = crp->crp_desc;
- crd->crd_skip = 0;
- crd->crd_key = key;
- crd->crd_klen = sizeof(key);
- crd->crd_len = sizeof(block_to_encrypt);
- crd->crd_flags = CRD_F_KEY_EXPLICIT;
- crd->crd_next = NULL;
- crd->crd_alg = CRYPTO_SHA2_256_HMAC;
- crp->crp_session = ds_session;
- crp->crp_flags = CRYPTO_F_CBIFSYNC;
- //crp->crp_flags = 0;
- crp->crp_buf = block_to_encrypt;
- //crp->crp_ilen = sizeof(block_to_encrypt);
- crp->crp_opaque = ds_session;
- crp->crp_callback = hmac_cmplted_cb;
- error = crypto_dispatch(crp);
- uprintf("Error %d\n", error);
- if ((crypto_ses2caps(ds_session) & CRYPTOCAP_F_SYNC) == 0) {
- uprintf("OMG\n");
- mtx_lock(&ds_lock);
- if (!error && !(crp->crp_flags & CRYPTO_F_DONE))
- error = msleep(crp, &ds_lock, 0, "gssdes", 0);
- mtx_unlock(&ds_lock);
- }
- u_int8_t *result = crp->crp_buf;
- result = NULL;
- uprintf("Error %d\n", error);
- uprintf("output length %d\n", crp->crp_olen);
- /*for(int i=0; i < crp->crp_olen ; i++)
- {
- uprintf("%x\n", result[i]);
- }*/
- crypto_freereq(crp);
- crypto_freesession(ds_session);
- uprintf("Exiting HMAC_test_function\n");
- }
- /* The function called at load/unload */
- static int event_handler(struct module *mod, int event, void *arg) {
- int e = 0; /* Error, 0 for normal return status */
- switch (event) {
- case MOD_LOAD:
- uprintf("Hello!\n");
- hmac_test();
- break;
- case MOD_UNLOAD:
- uprintf("Bye!\n");
- break;
- default:
- e = EOPNOTSUPP;
- break;
- }
- return (e);
- }
- /* The second argument of DECLARE_MODULE */
- static moduledata_t kdw_conf = {
- "kdw", /* module name */
- event_handler,
- NULL /* extra data */
- };
- DECLARE_MODULE(kdw, kdw_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
Add Comment
Please, Sign In to add comment