7139 Sync mDNS with mDNSResponder-625.41.2
[unleashed.git] / usr / src / cmd / cmd-inet / usr.lib / mdnsd / CryptoAlg.h
blobc21507e4b112ccd90409d7eb16fb30bbdea1e5a9
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __CRYPTO_ALG_H
19 #define __CRYPTO_ALG_H
21 typedef enum
23 CRYPTO_ALG,
24 DIGEST_ALG,
25 ENC_ALG,
26 } AlgType;
28 typedef struct
30 void *context;
31 AlgType type;
32 mDNSu8 alg;
33 } AlgContext;
35 typedef struct
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;
49 mDNSexport mStatus DigestAlgInit(mDNSu8 digestType, AlgFuncs *func);
50 mDNSexport mStatus CryptoAlgInit(mDNSu8 algType, AlgFuncs *func);
51 mDNSexport mStatus EncAlgInit(mDNSu8 algType, AlgFuncs *func);
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);
62 #endif // __CRYPTO_ALG_H