/*****************************************************************************
 *
 * HMAC MD5 engine test.
 * Copyright (C) 2001  Bart Trojanowski <bart@jukie.net>.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 *****************************************************************************/

#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
#include "engine.h"
#include "engine-debug.h"
#include "digest-hmac_md5.h"

static struct generic_engine *engine = NULL;

static u8 key[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
static u8 src[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
static u8 dst[32] = {0,};

static void test_digest_hmac_md5_callback( struct generic_job * );

static int 
test_digest_hmac_md5( void )
{
  int ret;
  struct generic_context *con;
  struct digest_hmac_md5_context_definition defn;
  struct generic_job *job;
  
  FIN();
    
  defn.key_ptr = key;
  defn.key_len = sizeof(key);
  
  ret = create_context( engine, &defn, GFP_ATOMIC, &con);
  if( ret ) goto done;
  
  ret = create_job( con, GFP_ATOMIC, &job );
  if( ret ) goto bail_has_con;
  
  job->data.in_ptr = src;
  job->data.in_len = sizeof(src);
  job->data.out_ptr = dst;
  job->data.out_len = sizeof(dst);
  job->callback = test_digest_hmac_md5_callback;
  job->opaque = con;
  
  ret = execute_job( job );
  if( ret )
    goto bail_has_job;
  
  /* all the releasing is done in the callback */
  goto done;

 bail_has_job:
  release_job( &job );
  
 bail_has_con:
  release_context(&con);
  
 done:
  FEXIT(ret==0);
  return ret;
}

static void 
test_digest_hmac_md5_callback( struct generic_job *job )
{
  struct generic_context *con = (void*)job->opaque;
  
  FIN();

  /* dump it */
  
  ge_data_dump("src", job->data.in_ptr, job->data.in_len);
  ge_data_dump("dst", job->data.out_ptr, job->data.out_len);
  
  /* release the stuff */
  release_job( &job );
  release_context( &con );
  
  FOUT();
}


/* -------------------------------------------------------------------------
 * MODULE FUNCTIONS
 * ------------------------------------------------------------------------- */

static int __init
test_init(void)
{
  int ret = 0;

  FIN();
  
  printk(KERN_INFO "MD5 engine test\n");
  
  ret = -ENODEV;
  engine = get_engine_by_name("digest-hmac_md5");
  if( !engine ) goto done;
  
  ret = test_digest_hmac_md5();
  
  FOUT();

 done:
  return ret;
}

static void __init
test_cleanup(void)
{
  FIN();

  if( engine )
    put_engine(engine);
  
  FOUT();
}

module_init(test_init);
module_exit(test_cleanup);

/*****************************************************************************
 *
 * $Log: test-digest-hmac_md5.c,v $
 * Revision 1.1  2001/06/08 23:29:10  bart
 * major refining
 *
 * Revision 1.4  2001/06/07 00:41:49  bart
 * removed a stupid printk line
 *
 * Revision 1.3  2001/06/04 02:14:02  bart
 * merged forward/reverse into one call 'process' which is a function pointer
 * to a specific processor decided in create_context (i.e. con_init)
 *
 * Revision 1.2  2001/06/03 15:23:02  bart
 * fixed ref count bug with context
 *
 * Revision 1.1  2001/06/03 13:17:20  bart
 * added testing facilities
 *
 *
 *****************************************************************************/

