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