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

📄 ibe.h

📁 voltage 公司提供的一个开发Ibe的工具包
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2003-2004, Voltage Security, all rights reserved.
 */

#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "paramobj.h"
#include "algobj.h"
#include "keyobj.h"
#include "mpint.h"
#ifndef ICTK_EXPOSE_PARAM_STRUCT
#define ICTK_EXPOSE_PARAM_STRUCT
#endif
#include "ictk.h"
#include "xbn_z.h"

#ifndef _IBE_H
#define _IBE_H

#ifdef __cplusplus
extern "C" {
#endif

/* Set the object with the curve data given. It allocates and fills in
 * the contexts.
 * <p>This function will make no argument checks, it is the
 * responsibility of the caller to make no errors. The base point is
 * not allowed to be infinity.
 *
 * @param obj The algorithm object to set.
 * @param curveInfo Contains the curve parameters.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltSetIBECurve VOLT_PROTO_LIST ((
   VoltParameterObject *obj,
   VtBFType1IBECurveInfo *curveInfo
));

/* This is how a type 1 curve is stored internally.
 */
typedef struct
{
  VtBFType1IBECurveInfo curveData;
  bf_context_t *bfCtx;
} VoltBFType1IBECurve;

/* Set the object with the param data given. It allocates and fills in
 * the contexts.
 *
 * @param obj The algorithm object to set.
 * @param paramInfo Contains the parameters.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltSetIBEParams VOLT_PROTO_LIST ((
   VtParameterObject paramObj,
   VtBFType1IBEParamInfo *curveInfo
));

/* This is how type 1 params are stored internally.
 */
typedef struct
{
  VtBFType1IBEParamInfo paramInfo;
  VtItem masterSecret;
  bf_context_t *bfCtx;
} VoltBFType1IBEParams;

/* Implements VCopyParams.
 */
int VOLT_CALLING_CONV BFType1IBECopyCurve VOLT_PROTO_LIST ((
   Pointer sourceParamObj,
   Pointer destParamObj
));

/* Implements VCtxDestroy.
 */
void VOLT_CALLING_CONV BFType1IBECurveDataDestroy VOLT_PROTO_LIST ((
   Pointer obj,
   Pointer ctx
));

/* Implements VCopyParams.
 * <p>Note: This Copy routine does NOT copy the master secret.
 */
int VOLT_CALLING_CONV BFType1IBECopyParams VOLT_PROTO_LIST ((
   Pointer sourceParamObj,
   Pointer destParamObj
));

/* Implements VCtxDestroy.
 */
void VOLT_CALLING_CONV BFType1IBEParamDataDestroy VOLT_PROTO_LIST ((
   Pointer obj,
   Pointer ctx
));

typedef VtBFType1IBEPubKeyInfo VoltBFType1IBEPubKeyData;

/* The primeLen field is the length, in bytes, of the prime.
 */
typedef struct
{
  VtBFType1IBEPriKeyInfo keyInfo;
  unsigned int primeLen;
} VoltBFType1IBEPriKeyData;

/* IBE decryption needs to decrypt the data to determine if it's valid.
 * The decryptedData field holds it. When encrypting it will be ignored.
 */
typedef struct
{
  VtItem encodedId;
  VtItem privateValue;
  VtItem processedData;
  bf_context_t *bfCtx;
} VoltBFType1IBECtx;

/* Check the contents of the curveInfo to see if the values are valid,
 * if the sizes or other attributes are supported.
 *
 * @param libCtx The libCtx to use if one is needed.
 * @param curveInfo The input curve to check.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltCheckCurve VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtBFType1IBECurveInfo *curveInfo
));

/* Check the contents of the paramInfo to see if the values are valid,
 * if the sizes or other attributes are supported.
 *
 * @param libCtx The libCtx to use if one is needed.
 * @param paramInfo The input curve to check.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltCheckParams VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtBFType1IBEParamInfo *paramInfo
));

/* The bfCtxCache is for keeping various bfCtx's around for reuse, so
 * we don't have to keep building them (an expensive operation).
 * <p>We don't expect to build too many of them, so we'll make it a
 * link list. An entry in the list is the ctx itself, a reference count
 * (keeping track of how many entities are currently using the ctx)
 * along with pointers to the previous and next entries.
 * <p>The search criteria is prime, subprime and base point.
 * <p>The cache itself is just the list and a count. We can put a limit
 * on the number of entries. If we get too many, delete any with a
 * referenceCount of 0 and build a new one.
 */
typedef struct
{
  unsigned int referenceCount;
  VtItem primeP;
  VtItem subprimeQ;
  VtItem xCoordBasePointG;
  unsigned int yCoordLowBit;
  bf_context_t *bfCtx;
  Pointer previousEntry;
  Pointer nextEntry;
} VoltBfCtxCacheEntry;

typedef struct
{
  unsigned int count;
  VoltBfCtxCacheEntry *cacheList;
} VoltBfCtxLocalCache;

/* Return a bfCtx using the supplied curve and public point.
 * <p>Pass in a NULL for the public point if it is not available. If
 * the routine does not have a public point, it will use the base point
 * as a "filler" or "placeholder".
 * <p>The caller passes in an address where this function will deposit
 * a bfCtx.
 * <p>In the curve and pubPointP, if a y-coordinate is NULL, the
 * function assumes the x-coordinate is set with the first byte
 * indicating the y-bit.
 * <p>You must pass in a valid curve. This function will not check the
 * validity of the curve. The curve arg cannot be NULL.
 * <p>You should pass a public point and the x-coordinates of all
 * points to get a "correct" bfCtx. If you don't have one of those
 * values, the function will return a bfCtx, but you should not use it
 * to do encryption or decryption. Use it to find, for example, the
 * x-coordinate.
 * <p>That is, if you pass a NULL pubPointP, the function will still
 * build a bfCtx so you can do work, but it will not be a "correct"
 * bfCtx.
 * <p>Also, if one or more of the points you pass does not contain the
 * x-coordinate, the function will still build a bfCtx so you can do
 * work, but it will not be a "correct" bfCtx. For example, use the
 * returned bfCtx to determine the x-coordinate from the y-coordinate.
 *
 * @param libCtx The library context to use.
 * @param mpCtx The MpIntCtx to use for IBE math.
 * @param curve Contains the prime, subprime and base point.
 * @param pubPointP The public point, if available, NULL if not.
 * @param bfCtx The address where the routine will deposit the bfCtx.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltGetBfCtxFromIBEParams VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtMpIntCtx mpCtx,
   VtBFType1IBECurveInfo *curve,
   VtBFType1IBEPoint *pubPointP,
   bf_context_t **bfCtx
));

typedef struct VoltBfCtxCacheDef VoltBfCtxCache;

/* Search the bfCtxCache for the bfCtx associated with the given curve.
 * If it finds a matching bfCtx, it sets the input pointer bfCtx to that
 * ctx (not the cache entry, but the ctx itself). It will also increment
 * the referenceCount in the cache entry.
 * <p>If the implementation cannot find a matching ctx, it will set the
 * input pointer bfCtx to NULL and return 0. Note that a return of 0 does
 * not mean the function found a bfCtx, but rather successfully searched,
 * which can very well mean it found no match.
 *
 * @param libCtx The libCtx to use.
 * @param bfCtxCache The cache to search.
 * @param curve The struct that contains the prime, subprime and base
 * point for which the bfCtx is needed.
 * @param bfCtx The address where the function will deposit a pointer
 * to the found bfCtx, or a NULL if no ctx was found.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VSearchBfCtxCache) VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VoltBfCtxCache *bfCtxCache,
   VtBFType1IBECurveInfo *curve,
   bf_context_t **bfCtx
));

/* Add the given bfCtx (referenced by the info in curveInfo) to the
 * bfCtxCache.
 *
 * @param libCtx The libCtx to use.
 * @param bfCtxCache The cache to which the ctx is added.
 * @param curveInfo Contains the prime, etc., the reference against
 * which the bfCtx is stored.
 * @param bfCtx The ctx to store.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VAddToBfCtxCache) VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VoltBfCtxCache *bfCtxCache,
   VtBFType1IBECurveInfo *curveInfo,
   bf_context_t *bfCtx

⌨️ 快捷键说明

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