⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getkeys.cpp

📁 voltage 公司提供的一个开发Ibe的工具包
💻 CPP
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getkeys.h"

#ifdef __cplusplus
extern "C"  {
#endif

int GetFixedDsaParams (
   VtLibCtx libCtx,
   VtMpIntCtx mpCtx,
   VtParameterObject *dsaParamObj
   )
{
  int status;
  VtParameterObject newObj = (VtParameterObject)0;
  VtDSAParamInfo paramInfo;
  VtParameterImpl *ParamImpl = VtParameterImplDefault;
  Pointer paramImplInfo = (Pointer)0;
  unsigned char primeP[128] = {
    0xb1, 0xbf, 0x76, 0xd5, 0x8b, 0x49, 0xb2, 0x2f,
    0x85, 0xce, 0x53, 0x71, 0x8e, 0x89, 0x98, 0x80,
    0xea, 0x7a, 0x7e, 0xb5, 0x6d, 0xd9, 0x53, 0x4a,
    0x5b, 0x28, 0xcc, 0x26, 0x40, 0x4c, 0xeb, 0xa9,
    0xf7, 0xb3, 0xf4, 0x9e, 0x80, 0x8e, 0x91, 0x65,
    0x18, 0xc6, 0x47, 0x0b, 0xa8, 0xd4, 0x7c, 0x93,
    0x6d, 0xcd, 0x35, 0xba, 0x00, 0x32, 0x94, 0xd2,
    0xef, 0x7c, 0x6d, 0xe1, 0x21, 0xa5, 0x88, 0x01,
    0xbe, 0x0e, 0x84, 0xe7, 0x4f, 0xe3, 0x32, 0x1c,
    0x6f, 0x51, 0xaf, 0x0c, 0x5f, 0x5a, 0xd8, 0xc2,
    0xd1, 0xea, 0xe3, 0x93, 0x00, 0x2a, 0x91, 0x5e,
    0xd9, 0x3d, 0x3b, 0x29, 0xa4, 0x97, 0xaf, 0xa8,
    0xfd, 0xf4, 0x64, 0xc4, 0x32, 0xcd, 0xad, 0xa9,
    0xb9, 0x9a, 0x27, 0x51, 0x19, 0x57, 0x84, 0x25,
    0x90, 0x95, 0x57, 0x3c, 0x31, 0x59, 0x9a, 0x9e,
    0xa5, 0x6f, 0x6a, 0x80, 0x1b, 0x71, 0xde, 0xad
  };
  unsigned char subprimeQ[20] = {
    0xc7, 0x94, 0xcd, 0x20, 0xc9, 0x4c, 0xe8, 0xae,
    0xb1, 0xa2, 0xdc, 0x33, 0x55, 0xb3, 0x21, 0xdd,
    0x93, 0x13, 0x31, 0x2f
  };
  unsigned char baseG[128] = {
    0x0a, 0xa6, 0x0d, 0xb7, 0xdd, 0xb0, 0xa2, 0xa4,
    0x2f, 0xa5, 0x70, 0xad, 0x6c, 0x44, 0xa0, 0x4f,
    0x3d, 0x26, 0xe0, 0x10, 0x05, 0x14, 0xc8, 0x24,
    0xdf, 0x13, 0x35, 0x0b, 0x8d, 0xd0, 0x9b, 0x11,
    0xa9, 0xe5, 0x52, 0xcf, 0x0c, 0x49, 0xd5, 0xb8,
    0xdd, 0x0e, 0x35, 0xd2, 0x6b, 0x9d, 0x12, 0x44,
    0xd0, 0x7b, 0x6e, 0xc6, 0x89, 0xf6, 0x26, 0xb9,
    0x5a, 0x14, 0x56, 0x7b, 0x1c, 0x1f, 0x5c, 0x07,
    0x64, 0x7a, 0xff, 0xf1, 0xa4, 0xb3, 0x15, 0xef,
    0x45, 0xa8, 0x21, 0x44, 0xfe, 0x35, 0x02, 0x6c,
    0xed, 0x67, 0xa9, 0x55, 0x4e, 0x34, 0x02, 0x6d,
    0x3d, 0xb9, 0xb6, 0x97, 0x49, 0x12, 0x57, 0x75,
    0xe4, 0x6f, 0x31, 0x5a, 0x4f, 0x02, 0x49, 0x51,
    0xa4, 0x2e, 0x9b, 0xdc, 0x71, 0xb0, 0xdc, 0x0b,
    0x4e, 0x5b, 0x7a, 0x62, 0xdf, 0x83, 0x60, 0x07,
    0x8d, 0x30, 0xfe, 0x2d, 0xc8, 0xca, 0x33, 0x1d
  };

  /* Init the return to NULL, if successful, set it then.
   */
  *dsaParamObj = (VtParameterObject)0;

  do
  {
    if (mpCtx != (VtMpIntCtx)0)
    {
      ParamImpl = VtParameterImplMpCtx;
      paramImplInfo = (Pointer)mpCtx;
    }

    status = VtCreateParameterObject (
      libCtx, ParamImpl, paramImplInfo, &newObj);
    if (status != 0)
      break;

    paramInfo.primeP.data = primeP;
    paramInfo.primeP.len = sizeof (primeP);
    paramInfo.subprimeQ.data = subprimeQ;
    paramInfo.subprimeQ.len = sizeof (subprimeQ);
    paramInfo.baseG.data = baseG;
    paramInfo.baseG.len = sizeof (baseG);
    status = VtSetParameterParam (
      newObj, VtParameterParamDSAParams, (Pointer)&paramInfo);
    if (status != 0)
      break;

    *dsaParamObj = newObj;

  } while (0);

  if (status == 0)
    return (0);

  /* If error, destroy what we created.
   */
  VtDestroyParameterObject (&newObj);

  return (status);
}

int BuildDsaKeyPair (
   VtLibCtx libCtx,
   VtMpIntCtx mpCtx,
   VtRandomObject strongSeedRandom,
   VtParameterObject dsaParamObj,
   VtKeyObject *pubKey,
   VtKeyObject *priKey
   )
{
  int status;
  unsigned int primeSizeBits;
  VtKeyImpl *KeyImpl = VtKeyImplDefault;
  Pointer keyImplInfo = (Pointer)0;

  *pubKey = (VtKeyObject)0;
  *priKey = (VtKeyObject)0;

  do
  {
    if (mpCtx != (VtMpIntCtx)0)
    {
      KeyImpl = VtKeyImplMpCtx;
      keyImplInfo = (Pointer)mpCtx;
    }

    /* Create new objects.
     */
    status = VtCreateKeyObject (libCtx, KeyImpl, keyImplInfo, pubKey);
    if (status != 0)
      break;

    status = VtCreateKeyObject (libCtx, KeyImpl, keyImplInfo, priKey);
    if (status != 0)
      break;

    if (dsaParamObj == (VtParameterObject)0)
    {
      /* Generate new params and then the key pair. It is faster to use
       * existing params and it doesn't affect security, so for your
       * application you may want to use VtKeyPairGenDSA. But it's just
       * as easy to write the code to generate new params, and because
       * generating new key pairs is not something done often, the extra
       * time will likely not be a problem, you might want to go ahead
       * and generate new params each time.
       */
      primeSizeBits = 1024;
      status = VtGenerateKeyPair (
        VtKeyPairGenDSAAndParams, (Pointer)&primeSizeBits, strongSeedRandom,
        *pubKey, *priKey);
    }
    else
    {
      /* Generate a key pair from existing params. It's quicker.
       */
      status = VtGenerateKeyPair (
        VtKeyPairGenDSA, (Pointer)dsaParamObj, strongSeedRandom,
        *pubKey, *priKey);
    }

  } while (0);

  if (status == 0)
    return (0);

  /* If there was an error, destroy the objects we created.
   */
  VtDestroyKeyObject (pubKey);
  VtDestroyKeyObject (priKey);

  return (status);
}

#ifdef  __cplusplus
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -