pad.h

来自「IBE是一种非对称密码技术」· C头文件 代码 · 共 129 行

H
129
字号
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */

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

#ifndef _PAD_H
#define _PAD_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct VtPaddingInfoDef
{
  Pointer info;
} VoltPaddingInfo;

/* Call this routine to perform padding. Not all instances will have
 * padding.
 * <p>This function takes as input a buffer that is of block size.
 * Inside the block is data to pad. This routine will format the block
 * to be a padded block.
 * <p>For example, padding an AES block following PKCS #5 would do this.
 *         ------------------------------------
 *  input: | 7 bytes input <9 bytes "nothing"> |
 *         ------------------------------------
 *         ------------------------------------
 * output: | 7 bytes input 09 09    ...    09  |
 *         ------------------------------------
 * In this example, the block argument would be the buffer containing
 * the data to pad. It must be 16 bytes big. The inputLen argument
 * would be 7 and the blockSize argument would be 16. The input data
 * stayed the same, but the padding function paced nine bytes of 09
 * after the input.
 * <p>Another example would be PKCS #1 Block 02 pad (1024-bit key).
 *         ------------------------------------------------------
 *  input: | 16 bytes input <112 bytes "nothing">                |
 *         ------------------------------------------------------
 *         ------------------------------------------------------
 * output: | 00 02 <109 non-zero random bytes> 00 16 bytes input |
 *         ------------------------------------------------------
 * In this example, the block argument would be the buffer containing
 * the data to pad. It must be 128 bytes big. The inputLen argument
 * would be 16 and the blockSize argument would be 128. The padding
 * function moved the input to the end of the block and placed the
 * appropriate padding ahead of it.
 * <p>It is possible to produce an error. For example, some padding
 * schemes require a minimum or maximum number of bytes of input.
 *
 * @param obj The algorithm object in control of the encryption.
 * @param random A random object to use if random bytes are needed.
 * @param padCtx The padding context.
 * @param block The input/output buffer, of block size. Upon entry it
 * contains the data to pad (which could be 0 bytes) and upon exit it
 * contains the padded block.
 * @param inputLen The length of the data to pad.
 * @param blockSize The size of the block to pad.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VPad) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   VtRandomObject random,
   Pointer padCtx,
   unsigned char *block,
   unsigned int inputLen,
   unsigned int blockSize
));

/* Call this routine to unpad a block.
 * <p>This function takes as input a buffer that is of block size.
 * Inside the block is padded data. This routine will strip the padding
 * and leave the data.
 * <p>For example, an AES PKCS #5 padded block would be unpadded as
 * follows.
 *         ------------------------------------
 *  input: |  <7 bytes>    09 09    ...    09  |
 *         ------------------------------------
 *         ------------------------------------
 * output: |  <7 bytes>    09 09    ...    09  |
 *         ------------------------------------
 * In this example, the block argument would be the buffer containing
 * the data to unpad. It would be 16 bytes big. The blockSize argument
 * would be 16. After the call, the buffer would look the same, but the
 * outputLen value would be set to 7.
 * <p>Another example would be PKCS #1 Block 02 pad (1024-bit key).
 *         ------------------------------------------------------
 *  input: | 00 02 <109 non-zero random bytes> 00 16 bytes input |
 *         ------------------------------------------------------
 *         ------------------------------------------------------
 * output: | 16 bytes input <112 bytes "nothing">                |
 *         ------------------------------------------------------
 * In this example, the block argument would be the buffer containing
 * the data to unpad. It would be 128 bytes big. The blockSize argument
 * would be 128. The unpadding function would check the pad bytes to
 * make sure they were all correct (00 and 02 at the front), then move
 * the data bytes from the end of the block to the beginning.
 * <p>It is possible to produce an error. For example, PKCS #5 requires
 * all pad bytes to be the same (e.g. 9 bytes of 09, or 15 bytes of 0F).
 *
 * @param obj The algorithm object in charge of the decryption.
 * @param padCtx The padding context.
 * @param block The input/output buffer, of block size. Upon entry it
 * contains a padded block and upon exit it points to the unpadded data.
 * @param blockSize The size of the block to pad.
 * @param outputLen The function will deposit at this address the
 * length of the unpadded data.
 * @return an int, 0 if the function completed successfully or a
 * non-zero error code.
 */
typedef int VOLT_CALLING_CONV (*VUnpad) VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   Pointer padCtx,
   unsigned char *block,
   unsigned int blockSize,
   unsigned int *outputLen
));

#ifdef __cplusplus
}
#endif

#endif /* _PAD_H */

⌨️ 快捷键说明

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