summaryrefslogtreecommitdiff
path: root/lib/dns/sec/dnssafe/ahchdig.c
blob: 8f4b4e23a6f75197dc96a7e1c9a65e7181a25d5c (plain)
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
/* 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 AHChooseDigest;
#define THIS_DIGEST struct AHChooseDigest

#include "global.h"
#include "algae.h"
#include "bsafe2.h"
#include "bkey.h"
#include "balg.h"
#include "balgmeth.h"
#include "ahchdig.h"
#include "amdigest.h"

static int InitDigestAlga PROTO_LIST
  ((AlgaChoice *, POINTER, B_ALGORITHM_METHOD *, A_SURRENDER_CTX *));

static AHDigestVTable V_TABLE = {
  AHChooseDigestDestructor, AHChooseDigestInit, AHChooseDigestUpdate,
  AHChooseDigestFinal
};

AHChooseDigest *AHChooseDigestConstructor2 (handler, infoType, info)
AHChooseDigest *handler;
struct B_AlgorithmInfoType *infoType;
POINTER info;
{
  if (handler == (AHChooseDigest *)NULL_PTR) {
    /* This constructor is being used to do a new */
    if ((handler = (AHChooseDigest *)T_malloc (sizeof (*handler)))
        == (AHChooseDigest *)NULL_PTR)
      return (handler);
  }

  /* Construct base class */
  AHDigestConstructor (&handler->digest);

  ALGA_CHOICE_Constructor (&handler->algaChoice, InitDigestAlga);
  handler->algaChoice._algorithmInfoType = infoType;
  handler->algaChoice._algorithmInfo = info;

  handler->digest.vTable = &V_TABLE;

  return (handler);
}

void AHChooseDigestDestructor (handler)
AHChooseDigest *handler;
{
  ALGA_CHOICE_Destructor (&handler->algaChoice);
  /* There is no desructor to call for the base class. */
}

int AHChooseDigestInit (handler, key, chooser, surrenderContext)
AHChooseDigest *handler;
B_Key *key;
B_ALGORITHM_CHOOSER chooser;
A_SURRENDER_CTX *surrenderContext;
{
  return (AlgaChoiceChoose
          (&handler->algaChoice, 0, key, chooser, surrenderContext));
}

int AHChooseDigestUpdate (handler, partIn, partInLen, surrenderContext)
AHChooseDigest *handler;
unsigned char *partIn;
unsigned int partInLen;
A_SURRENDER_CTX *surrenderContext;
{
  int status;
  
  if ((status = (*((A_DIGEST_ALGA *)handler->algaChoice._alga)->Update)
       (handler->algaChoice.context.z.context, partIn, partInLen,
        surrenderContext)) != 0)
    return (ConvertAlgaeError (status));
  return (0);    
}

int AHChooseDigestFinal
  (handler, partOut, partOutLen, maxPartOutLen, surrenderContext)
AHChooseDigest *handler;
unsigned char *partOut;
unsigned int *partOutLen;
unsigned int maxPartOutLen;
A_SURRENDER_CTX *surrenderContext;
{
  int status;
  
  if ((status = (*((A_DIGEST_ALGA *)handler->algaChoice._alga)->Final)
       (handler->algaChoice.context.z.context, partOut, partOutLen,
        maxPartOutLen, surrenderContext)) != 0)
    return (ConvertAlgaeError (status));
  return (0);    
}

static int InitDigestAlga
  (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_DIGEST_ALGA *)algorithmMethod->alga)->Query)
       (&contextSize, algaChoice->_algorithmInfo)) != 0)
    return (ConvertAlgaeError (status));

  if ((status = ResizeContextMakeNewContext
       (&algaChoice->context, contextSize)) != 0)
    return (status);

  if ((status = (*((A_DIGEST_ALGA *)algorithmMethod->alga)->Init)
       (algaChoice->context.z.context, algaChoice->_algorithmInfo,
        surrenderContext)) != 0)
    return (ConvertAlgaeError (status));

  return (0);
}