summaryrefslogtreecommitdiffstats
path: root/mDNSResponder/mDNSCore/CryptoAlg.h
blob: c21507e4b112ccd90409d7eb16fb30bbdea1e5a9 (plain) (blame)
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
/* -*- Mode: C; tab-width: 4 -*-
 *
 * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __CRYPTO_ALG_H
#define __CRYPTO_ALG_H

typedef enum
{
    CRYPTO_ALG,
    DIGEST_ALG,
    ENC_ALG,
} AlgType;

typedef struct
{
    void *context;
    AlgType type;
    mDNSu8 alg;
} AlgContext;

typedef struct
{
    mStatus (*Create)(AlgContext *ctx);
    mStatus (*Destroy)(AlgContext *ctx);
    mDNSu32 (*Length)(AlgContext *ctx);
    mStatus (*Add)(AlgContext *ctx, const void *data, mDNSu32 len);
    // Verify the ctx using the key and compare it against signature/siglen
    mStatus (*Verify)(AlgContext *ctx, mDNSu8 *key, mDNSu32 keylen, mDNSu8 *signature, mDNSu32 siglen);
    // Encode the data and return the encoded data
    mDNSu8* (*Encode)(AlgContext *ctx);
    // Return the finalized data in data whose length is len (used by hash algorithms)
    mStatus (*Final)(AlgContext *ctx, void *data, mDNSu32 len);
} AlgFuncs;

mDNSexport mStatus DigestAlgInit(mDNSu8 digestType, AlgFuncs *func);
mDNSexport mStatus CryptoAlgInit(mDNSu8 algType, AlgFuncs *func);
mDNSexport mStatus EncAlgInit(mDNSu8 algType, AlgFuncs *func);


extern AlgContext *AlgCreate(AlgType type, mDNSu8 alg);
extern mStatus AlgDestroy(AlgContext *ctx);
extern mDNSu32 AlgLength(AlgContext *ctx);
extern mStatus AlgAdd(AlgContext *ctx, const void *data, mDNSu32 len);
extern mStatus AlgVerify(AlgContext *ctx, mDNSu8 *key, mDNSu32 keylen, mDNSu8 *signature, mDNSu32 siglen);
extern mDNSu8* AlgEncode(AlgContext *ctx);
extern mStatus AlgFinal(AlgContext *ctx, void *data, mDNSu32 len);

#endif // __CRYPTO_ALG_H