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

📄 ibe.h

📁 IBE是一种非对称密码技术
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2003-2006, 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 BF 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 BF 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 BF type 1 params are stored internally.
 */
typedef struct
{
  VtBFType1IBEParamInfo   paramInfo;
  VtItem                  masterSecret;
  bf_context_t           *bfCtx;
} VoltBFType1IBEParams;

/* 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 VoltSetBBParams VOLT_PROTO_LIST ((
   VtParameterObject paramObj,
   VtBBType1IBEParamInfo *paramInfo
));

/* This is how BB type 1 params are stored internally.
 * The secretStruct is for getting the master secrets out of an object.
 * The data is stored as three VtItems as part of a struct. However,
 * they will need to be returned as an Info struct. However, that Info
 * struct is defined in vibeserver.h.
 */
typedef struct
{
  VtBBType1IBEParamInfo  paramInfo;
  Pointer                secretStruct;
  VtItem                 masterSecretAlpha;
  VtItem                 masterSecretBeta;
  VtItem                 masterSecretGamma;
  bb1_context_t         *bbCtx;
} VoltBBType1IBEParams;

/* 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 VCopyParams.
 * <p>Note: This Copy routine does NOT copy the master secret.
 */
int VOLT_CALLING_CONV BBType1IBECopyParams VOLT_PROTO_LIST ((
   Pointer sourceParamObj,
   Pointer destParamObj
));

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

/* Implements VCtxDestroy.
 */
void VOLT_CALLING_CONV BBType1IBEParamDataDestroy VOLT_PROTO_LIST ((
   Pointer paramObj,
   Pointer ctx
));

/* This is just like a VtKeyParam, except it takes an algorithm arg.
 * <p>VtKeyParamBFType1IBEPublic and VtKeyParamBBType1IBEPublic call
 * this subroutine to do the work. The only difference is which
 * algorithm the params must be (VOLT_PARAM_ALG_IBE_TYPE_1 or
 * VOLT_PARAM_ALG_BB_TYPE_1) and the key must be
 * (VOLT_KEY_ALG_IBE_TYPE_1 or VOLT_KEY_ALG_BB_TYPE_1).
 * <p>Pass VOLT_KEY_ALG_IBE_TYPE_1 or VOLT_KEY_ALG_BB_TYPE_1 for the
 * algorithm argument.
 */
int VOLT_CALLING_CONV VoltKeyParamIBEPublic VOLT_PROTO_LIST ((
   VtKeyObject object,
   Pointer info,
   unsigned int flag,
   unsigned int algorithm
));

typedef VtBFType1IBEPubKeyInfo VoltBFType1IBEPubKeyData;
typedef VoltBFType1IBEPubKeyData VoltBBType1IBEPubKeyData;

/* The primeLen field is the length, in bytes, of the prime.
 */
typedef struct
{
  unsigned int            primeLen;
  VtBFType1IBEPriKeyInfo  bfKeyInfo;
  VtBBType1IBEPriKeyInfo  bbKeyInfo;
} VoltIBEPriKeyData;

/*
 */
typedef struct
{
  VtItem         encodedId;
  VtItem         privateValue;
  VtItem         processedData;
  bf_context_t  *bfCtx;
} VoltBFType1IBECtx;

/*
 */
typedef struct
{
  VtItem          encodedId;
  VtItem          privateValue;
  VtItem          processedData;
  bb1_context_t  *bbCtx;
} VoltBBType1IBECtx;

/* 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
));

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

/* 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,
   unsigned int accelCount,
   unsigned char *accelTable,
   bf_context_t **bfCtx
));

/* This call will either release the ctx from the cache or it will
 * destroy it (bfDel).
 *
 * @param libCtx The libCtx to use.
 * @param bfCtx The address where the function will find the ctx to
 * release.
 * @return none.
 */
void VOLT_CALLING_CONV VoltReleaseBfCtx VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   bf_context_t **bfCtx
));

/* Return a bbCtx using the supplied params (prime, etc. including the
 * three public points).
 * <p>If the public points are NULL, the function will use "fake"
 * points as place holders. This will be useful if finding x
 * coordinates from y or vice versa.
 * <p>The caller passes in an address where this function will deposit
 * a bbCtx.
 * <p>In points, 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 (prime, subprime, base point).
 * This function will not check the validity of the curve.
 * <p>You should pass the real public points and the x-coordinates of
 * all points to get a "correct" bbCtx. If you don't have one of those
 * values, the function will return a bbCtx, 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 pubPointAlpha, the function will
 * still build a bbCtx so you can do work, but it will not be a
 * "correct" bbCtx.
 * <p>Also, if one or more of the points you pass does not contain the
 * x-coordinate, the function will still build a bbCtx so you can do
 * work, but it will not be a "correct" bbCtx. For example, use the
 * returned bbCtx to determine the x-coordinate from the y-coordinate.
 * <p>A caller might already have the acceleration tables built. If so,
 * there's no need to rebuild them. If accelG, accelG1, and accelG3 are
 * not NULL, each must contain accelCount points (each point consists
 * of 2 primeLen values). This function does no argument checking, so
 * the caller must not make a mistake.
 * <p>Of course, if accelG, accelG1, and accelG3 are NULL, the function
 * will build the acceleration tables.
 *
 * @param libCtx The library context to use.
 * @param mpCtx The MpIntCtx to use for IBE math.
 * @param paramInfo Contains the prime, subprime, base point, etc.
 * @param accelCount How many points are in each acceleration table.
 * @param accelG
 * @param accelG1
 * @param accelG3
 * @param bbCtx The address where the routine will deposit the bbCtx.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltGetBbCtxFromIBEParams VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VtMpIntCtx mpCtx,
   VtBBType1IBEParamInfo *paramInfo,
   unsigned int accelCount,
   unsigned char *accelG,
   unsigned char *accelG1,
   unsigned char *accelG3,
   bb1_context_t **bbCtx
));

/* This call will either release the ctx from the cache or it will
 * destroy it (bb1Del).
 *
 * @param libCtx The libCtx to use.
 * @param bbCtx The address where the function will find the ctx to
 * release.
 * @return none.
 */
void VOLT_CALLING_CONV VoltReleaseBbCtx VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   bb1_context_t **bbCtx
));

/* This function extracts the BB IBE params (prime, subprime,
 * basePoint, etc.) from a bb1_context_t (bbCtx) and puts them into
 * VtBBType1IBEParamInfo format.
 * <p>If you call this function, you must call DemolishBBIBEParams.
 *
 * @param libCtx The library context to use.
 * @param bfCtx The bfCtx containing the IBE information.
 * @param theParams The address where this routine will deposit a
 * pointer to the built ibeParams struct.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
int VOLT_CALLING_CONV VoltBuildIBEParamsFromBbCtx VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   bb1_context_t *bbCtx,
   VtBBType1IBEParamInfo **theParams
));

/* Demolish the BB ibeParams struct that was built by the

⌨️ 快捷键说明

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