1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an
unpublished work protected as such under copyright law. This work
contains proprietary, confidential, and trade secret information of
RSA Data Security, Inc. Use, disclosure or reproduction without the
express written authorization of RSA Data Security, Inc. is
prohibited.
*/
/* Define this so that the type of the 'this' pointer in the
virtual functions will be correct for this derived class.
*/
struct AHChooseRandom;
#define THIS_RANDOM struct AHChooseRandom
#include "port_before.h"
#include "global.h"
#include "algae.h"
#include "bsafe2.h"
#include "bkey.h"
#include "balg.h"
#include "balgmeth.h"
#include "ahchrand.h"
#include "amrandom.h"
#include "port_after.h"
static int InitRandomAlga PROTO_LIST
((AlgaChoice *, POINTER, B_ALGORITHM_METHOD *, A_SURRENDER_CTX *));
static AHRandomVTable V_TABLE = {
AHChooseRandomDestructor, AHChooseRandomInit, AHChooseRandomUpdate,
AHChooseRandomGenerateBytes
};
AHChooseRandom *AHChooseRandomConstructor2 (handler, infoType, info)
AHChooseRandom *handler;
struct B_AlgorithmInfoType *infoType;
POINTER info;
{
if (handler == (AHChooseRandom *)NULL_PTR) {
/* This constructor is being used to do a new */
if ((handler = (AHChooseRandom *)T_malloc (sizeof (*handler)))
== (AHChooseRandom *)NULL_PTR)
return (handler);
}
/* Construct base class */
AHRandomConstructor (&handler->random);
ALGA_CHOICE_Constructor (&handler->algaChoice, InitRandomAlga);
handler->algaChoice._algorithmInfoType = infoType;
handler->algaChoice._algorithmInfo = info;
handler->random.vTable = &V_TABLE;
return (handler);
}
void AHChooseRandomDestructor (handler)
AHChooseRandom *handler;
{
ALGA_CHOICE_Destructor (&handler->algaChoice);
/* There is no desructor to call for the base class. */
}
int AHChooseRandomInit (handler, chooser, surrenderContext)
AHChooseRandom *handler;
B_ALGORITHM_CHOOSER chooser;
A_SURRENDER_CTX *surrenderContext;
{
return (AlgaChoiceChoose
(&handler->algaChoice, 0, (B_Key *)NULL_PTR, chooser,
surrenderContext));
}
int AHChooseRandomUpdate (handler, input, inputLen, surrenderContext)
AHChooseRandom *handler;
unsigned char *input;
unsigned int inputLen;
A_SURRENDER_CTX *surrenderContext;
{
int status;
if ((status = (*((A_RANDOM_ALGA *)handler->algaChoice._alga)->Update)
(handler->algaChoice.context.z.context, input, inputLen,
surrenderContext)) != 0)
return (ConvertAlgaeError (status));
return (0);
}
int AHChooseRandomGenerateBytes (handler, output, outputLen, surrenderContext)
AHChooseRandom *handler;
unsigned char *output;
unsigned int outputLen;
A_SURRENDER_CTX *surrenderContext;
{
int status;
if ((status = (*((A_RANDOM_ALGA *)handler->algaChoice._alga)->Generate)
(handler->algaChoice.context.z.context, output, outputLen,
surrenderContext)) != 0)
return (ConvertAlgaeError (status));
return (0);
}
static int InitRandomAlga
(algaChoice, keyInfo, algorithmMethod, surrenderContext)
AlgaChoice *algaChoice;
POINTER keyInfo;
B_ALGORITHM_METHOD *algorithmMethod;
A_SURRENDER_CTX *surrenderContext;
{
int status;
unsigned int contextSize;
UNUSED_ARG (keyInfo)
if ((status = (*((A_RANDOM_ALGA *)algorithmMethod->alga)->Query)
(&contextSize, algaChoice->_algorithmInfo)) != 0)
return (ConvertAlgaeError (status));
if ((status = ResizeContextMakeNewContext
(&algaChoice->context, contextSize)) != 0)
return (status);
if ((status = (*((A_RANDOM_ALGA *)algorithmMethod->alga)->Init)
(algaChoice->context.z.context, algaChoice->_algorithmInfo,
surrenderContext)) != 0)
return (ConvertAlgaeError (status));
return (0);
}
|