xref: /titanic_52/usr/src/cmd/cmd-inet/usr.lib/mdnsd/CryptoAlg.h (revision f64ca10231919db05e806441ccd6186ea9c6e734)
1 /* -*- Mode: C; tab-width: 4 -*-
2  *
3  * Copyright (c) 2011 Apple Computer, 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 #ifndef __CRYPTO_ALG_H
18 #define __CRYPTO_ALG_H
19 
20 typedef enum
21 {
22     CRYPTO_ALG,
23     DIGEST_ALG,
24     ENC_ALG,
25 } AlgType;
26 
27 typedef struct
28 {
29     void *context;
30     AlgType type;
31     mDNSu8 alg;
32 } AlgContext;
33 
34 typedef struct
35 {
36     mStatus (*Create)(AlgContext *ctx);
37     mStatus (*Destroy)(AlgContext *ctx);
38     mDNSu32 (*Length)(AlgContext *ctx);
39     mStatus (*Add)(AlgContext *ctx, const void *data, mDNSu32 len);
40     // Verify the ctx using the key and compare it against signature/siglen
41     mStatus (*Verify)(AlgContext *ctx, mDNSu8 *key, mDNSu32 keylen, mDNSu8 *signature, mDNSu32 siglen);
42     // Encode the data and return the encoded data
43     mDNSu8* (*Encode)(AlgContext *ctx);
44     // Return the finalized data in data whose length is len (used by hash algorithms)
45     mStatus (*Final)(AlgContext *ctx, void *data, mDNSu32 len);
46 } AlgFuncs;
47 
48 mDNSexport mStatus DigestAlgInit(mDNSu8 digestType, AlgFuncs *func);
49 mDNSexport mStatus CryptoAlgInit(mDNSu8 algType, AlgFuncs *func);
50 mDNSexport mStatus EncAlgInit(mDNSu8 algType, AlgFuncs *func);
51 
52 
53 extern AlgContext *AlgCreate(AlgType type, mDNSu8 alg);
54 extern mStatus AlgDestroy(AlgContext *ctx);
55 extern mDNSu32 AlgLength(AlgContext *ctx);
56 extern mStatus AlgAdd(AlgContext *ctx, const void *data, mDNSu32 len);
57 extern mStatus AlgVerify(AlgContext *ctx, mDNSu8 *key, mDNSu32 keylen, mDNSu8 *signature, mDNSu32 siglen);
58 extern mDNSu8* AlgEncode(AlgContext *ctx);
59 extern mStatus AlgFinal(AlgContext *ctx, void *data, mDNSu32 len);
60 
61 #endif // __CRYPTO_ALG_H
62