RSA BSAFE Cert-C

Certificate Components for C

Crypto-C 6.2.1 Developer's Guide
Search

dummyrand.c

Implementation of a Crypto provider containing only a chooser and no random object. Use this provider when performing an operation which doesn't require random numbers.

/* $Id: dummyrand.c,v 1.4 2004/03/02 05:18:37 gsingh Exp $ */
/* dummyrand.c
** Copyright (c) 2001-2002, RSA Security Inc.
**
** This file is used to demonstrate how to interface to an RSA Security
** licensed development product.  You have a royalty-free right to use,
** modify, reproduce and distribute this demonstration file (including
** any modified version), provided that you agree that RSA Security has
** no warranty, implied or otherwise, or liability for this demonstration
** file or any modified version.
**
** This file contains a sample implementation of a Crypto provider which only
** contains a chooser and no random object.  The point of this sample provider
** is to avoid the overhead needed for random seeding.  You can use this
** provider when you are performing an operation which doesn't require random
** numbers.  If an operation returns an error E_NOT_SUPPORTED, then you've
** do need to register a Crypto provider which properly seeds a random object.
** Note also that this provider does not initialize the chooser with the
** methods needed to interface with CryptoAPI or PKCS #11.  Either use the
** default crypto provider, or update this provider with that ability.
*/

#include "certc.h"
#include "dummyrand.h"

#ifdef _MSC_VER
# pragma warning (disable: 171) /* invalid type conversion (often of very similar ptrs) */
#endif

/* We do not do any setup of the CAPI interface or PKCS #11 interface in this
 * chooser.
 */
static B_ALGORITHM_METHOD *FixedChooser[] = {
  &AM_SHA,
  &AM_SHA_RANDOM,
  &AM_RSA_CRT_ENCRYPT,
  &AM_RSA_CRT_DECRYPT,
  &AM_RSA_ENCRYPT,
  &AM_RSA_DECRYPT,
  &AM_DSA_SIGN,
  &AM_DSA_VERIFY,
  &AM_DES_EDE3_CBC_ENCRYPT,
  &AM_DES_EDE3_CBC_DECRYPT,
  &AM_DES_CBC_ENCRYPT,
  &AM_DES_CBC_DECRYPT,
  &AM_RC4_ENCRYPT,
  &AM_RC4_DECRYPT,
  &AM_RC2_CBC_DECRYPT,
  &AM_RC2_CBC_ENCRYPT,
  &AM_RC5_CBC_DECRYPT,
  &AM_RC5_CBC_ENCRYPT,
  &AM_MD5,
  &AM_MD2,
  (B_ALGORITHM_METHOD *)NULL_PTR,
};

static void Finalize (CERTC_CTX ctx, POINTER handle)
{
  UNUSED_ARG (ctx);
  UNUSED_ARG (handle);

  return;
}  /* end Finalize */

static int GetChooser (CERTC_CTX ctx, POINTER handle,
                       B_ALGORITHM_CHOOSER *chooser)
{
  UNUSED_ARG (ctx);
  UNUSED_ARG (handle);

  *chooser = FixedChooser;

  return 0;
}  /* end GetChooser */

static int GetRandomObject (CERTC_CTX ctx, POINTER handle,
                            B_ALGORITHM_OBJ *randomObj)
{
  UNUSED_ARG (handle);

  *randomObj = (B_ALGORITHM_OBJ)NULL_PTR;

  return (C_Log (ctx, E_NOT_SUPPORTED, ST_ERROR, __FILE__, __LINE__));
}  /* end GetRandomObject */

static void UpdateRandom (CERTC_CTX ctx, POINTER handle)
{
  UNUSED_ARG (ctx);
  UNUSED_ARG (handle);

  return;
}  /* end UpdateRandom */

int S_InitializeDummyRandomCSP (CERTC_CTX ctx, POINTER params,
                                SERVICE_FUNCS *funcs, POINTER *handle)
{
  CRYPTO_FUNCS *cryptoFuncs = (CRYPTO_FUNCS *)funcs;

  UNUSED_ARG (ctx);
  UNUSED_ARG (params);

  *handle = NULL_PTR;

  T_memset ((POINTER)funcs, 0, sizeof (*funcs));

  cryptoFuncs->Finalize = Finalize;
  cryptoFuncs->GetChooser = GetChooser;
  cryptoFuncs->GetRandomObject = GetRandomObject;
  cryptoFuncs->UpdateRandom = UpdateRandom;

  return 0;
}  /* end S_InitializeDummyRandomCSP */

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 067-001001-2720-001-000 - 2.7.2