~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject/third_party/srtp/crypto/include/cryptoalg.h

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * cryptoalg.h
3
 
 *
4
 
 * API for authenticated encryption crypto algorithms
5
 
 * 
6
 
 * David A. McGrew
7
 
 * Cisco Systems, Inc.
8
 
 */
9
 
/*
10
 
 *      
11
 
 * Copyright (c) 2001-2006 Cisco Systems, Inc.
12
 
 * All rights reserved.
13
 
 * 
14
 
 * Redistribution and use in source and binary forms, with or without
15
 
 * modification, are permitted provided that the following conditions
16
 
 * are met:
17
 
 * 
18
 
 *   Redistributions of source code must retain the above copyright
19
 
 *   notice, this list of conditions and the following disclaimer.
20
 
 * 
21
 
 *   Redistributions in binary form must reproduce the above
22
 
 *   copyright notice, this list of conditions and the following
23
 
 *   disclaimer in the documentation and/or other materials provided
24
 
 *   with the distribution.
25
 
 * 
26
 
 *   Neither the name of the Cisco Systems, Inc. nor the names of its
27
 
 *   contributors may be used to endorse or promote products derived
28
 
 *   from this software without specific prior written permission.
29
 
 * 
30
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31
 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32
 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33
 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34
 
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35
 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36
 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37
 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41
 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
42
 
 *
43
 
 */
44
 
 
45
 
#ifndef CRYPTOALG_H
46
 
#define CRYPTOALG_H
47
 
 
48
 
#include "err.h"
49
 
 
50
 
/**
51
 
 * @defgroup Crypto Cryptography
52
 
 *
53
 
 * Zed uses a simple interface to a cryptographic transform.
54
 
 *
55
 
 * @{
56
 
 */
57
 
 
58
 
/**
59
 
 * @brief applies a crypto algorithm
60
 
 *
61
 
 * The function pointer cryptoalg_func_t points to a function that
62
 
 * implements a crypto transform, and provides a uniform API for
63
 
 * accessing crypto mechanisms.
64
 
 * 
65
 
 * @param key       location of secret key                  
66
 
 *
67
 
 * @param clear     data to be authenticated but not encrypted           
68
 
 *
69
 
 * @param clear_len length of data to be authenticated but not encrypted
70
 
 *
71
 
 * @param iv        location to write the Initialization Vector (IV)
72
 
 *
73
 
 * @param protect   location of the data to be encrypted and
74
 
 * authenticated (before the function call), and the ciphertext
75
 
 * and authentication tag (after the call)
76
 
 *
77
 
 * @param protected_len location of the length of the data to be
78
 
 * encrypted and authenticated (before the function call), and the
79
 
 * length of the ciphertext (after the call)
80
 
 *
81
 
 */
82
 
                    
83
 
typedef err_status_t (*cryptoalg_func_t) 
84
 
     (void *key,            
85
 
      const void *clear,          
86
 
      unsigned clear_len,   
87
 
      void *iv,             
88
 
      void *protect,         
89
 
      unsigned *protected_len);
90
 
 
91
 
typedef 
92
 
err_status_t (*cryptoalg_inv_t)
93
 
     (void *key,            /* location of secret key                  */
94
 
      const void *clear,     /* data to be authenticated only           */
95
 
      unsigned clear_len,   /* length of data to be authenticated only */
96
 
      void *iv,             /* location of iv                          */
97
 
      void *opaque,         /* data to be decrypted and authenticated  */
98
 
      unsigned *opaque_len  /* location of the length of data to be
99
 
                             * decrypted and authd (before and after) 
100
 
                             */
101
 
      );
102
 
 
103
 
typedef struct cryptoalg_ctx_t {
104
 
  cryptoalg_func_t enc;
105
 
  cryptoalg_inv_t  dec;
106
 
  unsigned key_len;
107
 
  unsigned iv_len;
108
 
  unsigned auth_tag_len;
109
 
  unsigned max_expansion; 
110
 
} cryptoalg_ctx_t;
111
 
 
112
 
typedef cryptoalg_ctx_t *cryptoalg_t;
113
 
 
114
 
#define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len)
115
 
 
116
 
#define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len)
117
 
 
118
 
#define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len)
119
 
 
120
 
int
121
 
cryptoalg_get_id(cryptoalg_t c);
122
 
 
123
 
cryptoalg_t 
124
 
cryptoalg_find_by_id(int id);
125
 
 
126
 
 
127
 
/**
128
 
 * @}
129
 
 */
130
 
 
131
 
#endif /* CRYPTOALG_H */
132
 
 
133