]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/CryptoAlg.h
mDNSResponder-878.50.17.tar.gz
[apple/mdnsresponder.git] / mDNSCore / CryptoAlg.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #ifndef __CRYPTO_ALG_H
19 #define __CRYPTO_ALG_H
20
21 typedef enum
22 {
23 CRYPTO_ALG,
24 DIGEST_ALG,
25 ENC_ALG,
26 } AlgType;
27
28 typedef struct
29 {
30 void *context;
31 AlgType type;
32 mDNSu8 alg;
33 } AlgContext;
34
35 typedef struct
36 {
37 mStatus (*Create)(AlgContext *ctx);
38 mStatus (*Destroy)(AlgContext *ctx);
39 mDNSu32 (*Length)(AlgContext *ctx);
40 mStatus (*Add)(AlgContext *ctx, const void *data, mDNSu32 len);
41 // Verify the ctx using the key and compare it against signature/siglen
42 mStatus (*Verify)(AlgContext *ctx, mDNSu8 *key, mDNSu32 keylen, mDNSu8 *signature, mDNSu32 siglen);
43 // Encode the data and return the encoded data
44 mDNSu8* (*Encode)(AlgContext *ctx);
45 // Return the finalized data in data whose length is len (used by hash algorithms)
46 mStatus (*Final)(AlgContext *ctx, void *data, mDNSu32 len);
47 } AlgFuncs;
48
49 mDNSexport mStatus DigestAlgInit(mDNSu8 digestType, AlgFuncs *func);
50 mDNSexport mStatus CryptoAlgInit(mDNSu8 algType, AlgFuncs *func);
51 mDNSexport mStatus EncAlgInit(mDNSu8 algType, AlgFuncs *func);
52
53
54 extern AlgContext *AlgCreate(AlgType type, mDNSu8 alg);
55 extern mStatus AlgDestroy(AlgContext *ctx);
56 extern mDNSu32 AlgLength(AlgContext *ctx);
57 extern mStatus AlgAdd(AlgContext *ctx, const void *data, mDNSu32 len);
58 extern mStatus AlgVerify(AlgContext *ctx, mDNSu8 *key, mDNSu32 keylen, mDNSu8 *signature, mDNSu32 siglen);
59 extern mDNSu8* AlgEncode(AlgContext *ctx);
60 extern mStatus AlgFinal(AlgContext *ctx, void *data, mDNSu32 len);
61
62 #endif // __CRYPTO_ALG_H