Couchbase C Client  3.0.3
Asynchronous C Client for Couchbase
crypto.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2018-2020 Couchbase, Inc.
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 LCB_CRYPTO_H
19 #define LCB_CRYPTO_H
20 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
51 typedef struct lcbcrypto_SIGV {
52  const uint8_t *data;
53  size_t len;
55 
56 struct lcbcrypto_PROVIDER;
67 typedef struct lcbcrypto_PROVIDER {
68  uint16_t version;
69  int16_t _refcnt;
70  uint64_t flags;
71  void *cookie;
72  void (*destructor)(struct lcbcrypto_PROVIDER *provider);
73  union {
74  struct {
76  void (*release_bytes)(struct lcbcrypto_PROVIDER *provider, void *bytes);
78  lcb_STATUS (*generate_iv)(struct lcbcrypto_PROVIDER *provider, uint8_t **iv, size_t *iv_len);
80  lcb_STATUS (*sign)(struct lcbcrypto_PROVIDER *provider, const lcbcrypto_SIGV *inputs, size_t input_num,
81  uint8_t **sig, size_t *sig_len);
83  lcb_STATUS (*verify_signature)(struct lcbcrypto_PROVIDER *provider, const lcbcrypto_SIGV *inputs,
84  size_t input_num, uint8_t *sig, size_t sig_len);
86  lcb_STATUS (*encrypt)(struct lcbcrypto_PROVIDER *provider, const uint8_t *input, size_t input_len,
87  const uint8_t *iv, size_t iv_len, uint8_t **output, size_t *output_len);
89  lcb_STATUS (*decrypt)(struct lcbcrypto_PROVIDER *provider, const uint8_t *input, size_t input_len,
90  const uint8_t *iv, size_t iv_len, uint8_t **output, size_t *output_len);
92  const char *(*get_key_id)(struct lcbcrypto_PROVIDER *provider);
93  } v1;
94  } v;
96 
105 typedef struct lcbcrypto_FIELDSPEC {
106  const char *name;
107  const char *alg;
108  LCB_DEPRECATED2(const char *kid,
109  "Do not use kid field. Encryption keys have to be part of the provider implementation");
111 
118 typedef struct lcbcrypto_CMDENCRYPT {
119  uint16_t version;
120  const char *prefix;
121  const char *doc;
122  size_t ndoc;
123  char *out;
124  size_t nout;
126  size_t nfields;
128 
135 typedef struct lcbcrypto_CMDDECRYPT {
136  uint16_t version;
137  const char *prefix;
138  const char *doc;
139  size_t ndoc;
140  char *out;
141  size_t nout;
143  size_t nfields;
145 
170 LIBCOUCHBASE_API void lcbcrypto_register(lcb_INSTANCE *instance, const char *name, lcbcrypto_PROVIDER *provider);
171 
180 LIBCOUCHBASE_API void lcbcrypto_unregister(lcb_INSTANCE *instance, const char *name);
181 
187 LIBCOUCHBASE_API void lcbcrypto_ref(lcbcrypto_PROVIDER *provider);
188 
196 LIBCOUCHBASE_API void lcbcrypto_unref(lcbcrypto_PROVIDER *provider);
197 
201 #define LCBCRYPTO_DEFAULT_FIELD_PREFIX "__crypt_"
202 
236 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif /* LCB_CRYPTO_H */
lcbcrypto_unref
void lcbcrypto_unref(lcbcrypto_PROVIDER *provider)
Decrement reference counter for crypto-provider.
lcbcrypto_CMDENCRYPT::nout
size_t nout
size of the output JSON document
Definition: crypto.h:124
lcbcrypto_PROVIDER::destructor
void(* destructor)(struct lcbcrypto_PROVIDER *provider)
destructor function, or NULL
Definition: crypto.h:72
lcbcrypto_CMDENCRYPT::doc
const char * doc
pointer to the input JSON document
Definition: crypto.h:121
lcbcrypto_SIGV::len
size_t len
length of the data in bytes
Definition: crypto.h:53
lcbcrypto_SIGV
IOV-style structure for signing functions of crypto-provider.
Definition: crypto.h:51
lcbcrypto_encrypt_fields
lcb_STATUS lcbcrypto_encrypt_fields(lcb_INSTANCE *instance, lcbcrypto_CMDENCRYPT *cmd)
Encrypt all specified fields in the JSON encoded object.
lcbcrypto_PROVIDER::flags
uint64_t flags
provider-specific flags
Definition: crypto.h:70
lcbcrypto_unregister
void lcbcrypto_unregister(lcb_INSTANCE *instance, const char *name)
Unregister crypto-provider for specified alias.
lcbcrypto_ref
void lcbcrypto_ref(lcbcrypto_PROVIDER *provider)
Increment reference counter for crypto-provider.
lcbcrypto_CMDENCRYPT
Command to encrypt JSON fields.
Definition: crypto.h:118
lcb_STATUS
lcb_STATUS
Error codes returned by the library.
Definition: error.h:202
lcb_INSTANCE
struct lcb_st lcb_INSTANCE
Definition: couchbase.h:35
lcbcrypto_register
void lcbcrypto_register(lcb_INSTANCE *instance, const char *name, lcbcrypto_PROVIDER *provider)
Register crypto-provider for specified alias.
lcbcrypto_CMDENCRYPT::fields
lcbcrypto_FIELDSPEC * fields
list of field specs
Definition: crypto.h:125
lcbcrypto_decrypt_fields
lcb_STATUS lcbcrypto_decrypt_fields(lcb_INSTANCE *instance, lcbcrypto_CMDDECRYPT *cmd)
Decrypt all specified fields in the JSON encoded object.
lcbcrypto_CMDENCRYPT::nfields
size_t nfields
number of field specs
Definition: crypto.h:126
lcbcrypto_PROVIDER::version
uint16_t version
version of the structure, current value is 1
Definition: crypto.h:68
lcbcrypto_PROVIDER::_refcnt
int16_t _refcnt
reference counter
Definition: crypto.h:69
lcbcrypto_CMDENCRYPT::out
char * out
pointer to output JSON document.
Definition: crypto.h:123
lcbcrypto_SIGV::data
const uint8_t * data
pointer to data
Definition: crypto.h:52
lcbcrypto_FIELDSPEC::alg
const char * alg
crypto provider alias (NUL-terminated)
Definition: crypto.h:107
lcbcrypto_PROVIDER
Crypto-provider interface.
Definition: crypto.h:67
lcbcrypto_CMDENCRYPT::prefix
const char * prefix
prefix to encrypted field.
Definition: crypto.h:120
lcbcrypto_CMDDECRYPT
Command to decrypt JSON fields.
Definition: crypto.h:135
lcbcrypto_PROVIDER::cookie
void * cookie
opaque pointer (e.g.
Definition: crypto.h:71
lcbcrypto_CMDENCRYPT::ndoc
size_t ndoc
size of the input JSON document
Definition: crypto.h:122
lcbcrypto_FIELDSPEC
Structure for JSON field specification for encrypt/decrypt API.
Definition: crypto.h:105
lcbcrypto_FIELDSPEC::name
const char * name
field name (NUL-terminated)
Definition: crypto.h:106