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

📄 encode.h

📁 IBE是一种非对称密码技术
💻 H
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */

#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "algobj.h"

#ifndef _ENCODE_H
#define _ENCODE_H

#ifdef __cplusplus
extern "C" {
#endif

/* If the class is ENCODE, this is the classCtx (the data struct and
 * the types that are the fields).
 */

/* How big does the output buffer need to be to handle the input?
 * <p>The caller supplies the number of new bytes to process (this does
 * not include any bytes in the unprocessedData buffer). This function
 * will determine the size needed based on the size of the input, the
 * number of bytes in the unprocessedData buffer, whether encoding or
 * decoding and whether Update or Final.
 * <p>The caller must supply one of the following flags to indicate
 * whether the operation will be encrypt or decrypt and Update or Final.
 *
 *    VOLT_CALLER_ENCODE_UPDATE
 *    VOLT_CALLER_ENCODE_FINAL
 *    VOLT_CALLER_DECODE_UPDATE
 *    VOLT_CALLER_DECODE_FINAL
 *
 * <p>The implementation of this typedef must also determine if the
 * input length is valid. For Final calls, the input length given may
 * be invalid depending on padding.
 * <p>The caller also supplies the new input bytes in case the
 * implementation wants to examine them. Most algorithms will ignore
 * them, but for some, the input may need to be of a particular format.
 *
 * @param obj The algorithm object.
 * @param input The new input to process.
 * @param inputLen The length of new input to be processed.
 * @param outputSize The address where the implementation will go to
 * deposit the size required.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VGetEncodeOutputSize) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   unsigned int callFlag,
   unsigned char *input,
   unsigned int inputLen,
   unsigned int *outputSize,
   VtRandomObject random
));

#define VOLT_CALLER_ENCODE_UPDATE  1
#define VOLT_CALLER_ENCODE_FINAL   2
#define VOLT_CALLER_DECODE_UPDATE  3
#define VOLT_CALLER_DECODE_FINAL   4

/* The Init function simply sets the initial state.
 * <p> This function will do no argument checking, it is the
 * responsibility of the caller to make sure the input is correct.
 *
 * @param obj The algorithm object containing the context to set.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VEncodeInit) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj
));

/* Encode the given data. This function assumes the output buffer is
 * big enough (determined by calling GetEncodeOutputSize).
 * <p>The input might be one block, it might be several. But the caller
 * must pass in a multiple of the block size.
 * <p> This function will do no argument checking, it is the
 * responsibility of the caller to make sure the input is correct.
 *
 * @param obj The algorithm object containing the context to update.
 * @param random An algorithm object set and seeded to generate random
 * bytes if needed.
 * @param dataToEncode The data to encode.
 * @param dataToEncodeLen The length, in bytes, of the input.
 * @param encoding The buffer into which the function will place the
 * encoded result.
 * @param encodingLen The address where the function will deposit the
 * number of bytes placed into the output buffer.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VEncodeUpdate) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   VtRandomObject random,
   unsigned char *dataToEncode,
   unsigned int dataToEncodeLen,
   unsigned char *encoding,
   unsigned int *encodingLen
));

/* No more data, take care of any padding.
 * <p> This function will do no argument checking, it is the
 * responsibility of the caller to make sure the input is correct. For
 * example, the output buff must be big enough.
 *
 * @param obj The algorithm object containing the context.
 * @param random An algorithm object set and seeded to generate random
 * bytes if needed.
 * @param encoding The buffer into which the resulting encoded data
 * will be placed.
 * @param encodingLen The address where the function will deposit the
 * number of bytes placed into the output buffer.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VEncodeFinal) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   VtRandomObject random,
   unsigned char *encoding,
   unsigned int *encodingLen
));

/* The Init function simply sets the initial state.
 * <p> This function will do no argument checking, it is the
 * responsibility of the caller to make sure the input is correct.
 *
 * @param obj The algorithm object containing the context to set.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VDecodeInit) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj
));

/* Decode the data in the unprocessedData buffer. This function assumes
 * the output buffer is big enough (determined by calling
 * GetEncodeOutputSize).
 * <p>The input might be one block, it might be several. But the caller
 * must pass in a multiple of the block size.
 * <p> This function will do no argument checking, it is the
 * responsibility of the caller to make sure the input is correct.
 *
 * @param obj The algorithm object containing the context to update.
 * @param random An algorithm object set and seeded to generate random
 * bytes if needed.
 * @param dataToDecode The data to decode.
 * @param dataToDecodeLen The length, in bytes, of the input.
 * @param decoding The buffer into which the function will place the
 * decoded result.
 * @param decodingLen The address where the function will deposit the
 * number of bytes placed into the output buffer.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VDecodeUpdate) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   VtRandomObject random,
   unsigned char *dataToDecode,
   unsigned int dataToDecodeLen,
   unsigned char *decoding,
   unsigned int *decodingLen
));

/* No more data, take care of any padding.
 * <p> This function will do no argument checking, it is the
 * responsibility of the caller to make sure the input is correct. For
 * example, the output buff must be big enough.
 *
 * @param obj The algorithm object containing the context.
 * @param random An algorithm object set and seeded to generate random
 * bytes if needed.
 * @param decoding The buffer into which the resulting encoded data
 * will be placed.
 * @param decodingLen The address where the function will deposit the
 * number of bytes placed into the output buffer.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VDecodeFinal) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   VtRandomObject random,
   unsigned char *decoding,
   unsigned int *decodingLen
));

typedef struct
{
  VGetEncodeOutputSize GetEncodeOutputSize;
  VEncodeInit EncodeInit;
  VEncodeUpdate EncodeUpdate;
  VEncodeFinal EncodeFinal;
  VDecodeInit DecodeInit;
  VDecodeUpdate DecodeUpdate;
  VDecodeFinal DecodeFinal;
  unsigned char *unprocessedData;
  unsigned int unprocessedDataLen;
  unsigned int plainBlockSize;
  unsigned int codedBlockSize;
  Pointer localEncodeCtx;
  VCtxDestroy LocalEncodeCtxDestroy;
} VoltEncodeClassCtx;

#ifdef __cplusplus
}
#endif

#endif /* _ENCODE_H */

⌨️ 快捷键说明

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