Skip to content

Commit 88765f4

Browse files
authored
Initial commit, moving over the files from the ESDK and adding a README (#1)
* Initial commit, moving over the files from the ESDK and adding a README * review comments
1 parent 36b2fb2 commit 88765f4

25 files changed

+2566
-5
lines changed

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
## My Project
1+
## AWS Verification Model For LibCrypto
22

3-
TODO: Fill this README out!
3+
Formal verification tools, such as [CBMC](https://github.com/diffblue/cbmc), often require "verification models" of libraries in order to verify code that uses these libraries.
4+
These models provide an abstract implementation of the library API, as opposed to the concrete implementation the library itself provides.
5+
For example, the concrete implementation of a hash-function might invoke a complicated cryptographic routine.
6+
The abstract implementation, on the other hand, might simply assert that the pointers given are valid, and then return an "unconstrained" (AKA "non-deterministic") value.
7+
This allows verification tools to focus on the contracts guaranteed by the API, without having to spend time and memory analyzing the detailed implementation.
8+
It also helps make proofs robust against changes to the library implementation: as long as the library continues to implement the API described in the model, the proof will hold, even if the library changes.
49

5-
Be sure to:
10+
This repository contains a partial verification model for [libCrypto](https://github.com/openssl/openssl).
11+
In particular, it contains abstract models, written in C, of the particular functions used by projects that we have verified.
12+
We do not currently cover all, or even most, of the libCrypto API.
13+
And we do not cover all the functionality of the API that we do cover - in many cases, we model just enough to enable the proofs of other projects to go through.
614

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
15+
We welcome contributions modelling the remaining libCrypto functionality.
916

1017
## Security
1118

include/openssl/asn1.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
#ifndef HEADER_ASN1_H
18+
#define HEADER_ASN1_H
19+
20+
#include <openssl/ossl_typ.h>
21+
22+
void ASN1_STRING_clear_free(ASN1_STRING *a);
23+
BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
24+
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
25+
ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **ppin, long length);
26+
int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **ppout);
27+
28+
#endif /* HEADER_ASN1_H */

include/openssl/bio.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. You can obtain a copy
6+
* in the file LICENSE in the source distribution or at
7+
* https://www.openssl.org/source/license.html
8+
*/
9+
10+
#ifndef HEADER_BIO_H
11+
#define HEADER_BIO_H
12+
13+
#ifndef OPENSSL_NO_STDIO
14+
# include <stdio.h>
15+
#endif
16+
#include <stdarg.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
#include <openssl/ossl_typ.h>
22+
23+
typedef int pem_password_cb(char *buf, int size, int rwflag, void *u);
24+
25+
BIO *BIO_new_mem_buf(const void *buf, signed int len);
26+
27+
EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
28+
29+
EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
30+
31+
int BIO_free(BIO *a);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
#endif

include/openssl/bn.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
#ifndef HEADER_BN_H
18+
#define HEADER_BN_H
19+
20+
#include <openssl/ossl_typ.h>
21+
22+
BIGNUM *BN_new(void);
23+
BIGNUM *BN_dup(const BIGNUM *from);
24+
int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
25+
void BN_clear_free(BIGNUM *a);
26+
void BN_free(BIGNUM *a);
27+
28+
#endif

include/openssl/crypto.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
/* Empty header. */

include/openssl/ec.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
#ifndef HEADER_EC_H
18+
#define HEADER_EC_H
19+
20+
#include <openssl/asn1.h>
21+
#include <openssl/bn.h>
22+
#include <openssl/objects.h>
23+
#include <openssl/ossl_typ.h>
24+
25+
/** Enum for the point conversion form as defined in X9.62 (ECDSA)
26+
* for the encoding of a elliptic curve point (x,y) */
27+
typedef enum {
28+
/** the point is encoded as z||x, where the octet z specifies
29+
* which solution of the quadratic equation y is */
30+
POINT_CONVERSION_COMPRESSED = 2,
31+
/** the point is encoded as z||x||y, where z is the octet 0x04 */
32+
POINT_CONVERSION_UNCOMPRESSED = 4,
33+
/** the point is encoded as z||x||y, where the octet z specifies
34+
* which solution of the quadratic equation y is */
35+
POINT_CONVERSION_HYBRID = 6
36+
} point_conversion_form_t;
37+
38+
typedef struct ec_group_st EC_GROUP;
39+
40+
EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
41+
void EC_GROUP_set_point_conversion_form(EC_GROUP *group, point_conversion_form_t form);
42+
const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
43+
void EC_GROUP_free(EC_GROUP *group);
44+
45+
typedef struct ECDSA_SIG_st ECDSA_SIG;
46+
47+
EC_KEY *EC_KEY_new(void);
48+
int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
49+
void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
50+
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
51+
int EC_KEY_generate_key(EC_KEY *key);
52+
int EC_KEY_up_ref(EC_KEY *r);
53+
const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
54+
const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
55+
int EC_KEY_generate_key(EC_KEY *key);
56+
void EC_KEY_free(EC_KEY *key);
57+
58+
EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
59+
int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
60+
61+
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
62+
int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
63+
void ECDSA_SIG_free(ECDSA_SIG *sig);
64+
ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
65+
int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
66+
67+
#endif

include/openssl/ecdsa.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
/* Empty header */

include/openssl/err.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
#ifndef HEADER_ERR_H
18+
#define HEADER_ERR_H
19+
20+
#include <stdio.h>
21+
22+
void ERR_print_errors_fp(FILE *fp);
23+
24+
signed int ERR_get_error(void);
25+
26+
unsigned long ERR_peek_last_error(void);
27+
28+
#endif

include/openssl/evp.h

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Changes to OpenSSL version 1.1.1. copyright Amazon.com, Inc. All Rights Reserved.
3+
* Copyright 1995-2017 The OpenSSL Project Authors. 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+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
#ifndef HEADER_EVP_H
18+
#define HEADER_EVP_H
19+
20+
#include <stddef.h>
21+
22+
#include <openssl/ec.h>
23+
#include <openssl/ossl_typ.h>
24+
25+
#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */
26+
#define EVP_PKEY_HKDF 1036 // reference from obj_mac.h
27+
28+
EVP_PKEY *EVP_PKEY_new(void);
29+
EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey);
30+
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
31+
void EVP_PKEY_free(EVP_PKEY *pkey);
32+
EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
33+
EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
34+
int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
35+
int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
36+
int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen);
37+
void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
38+
int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2);
39+
int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
40+
int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx);
41+
int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
42+
int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad);
43+
int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
44+
int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
45+
int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen);
46+
int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen);
47+
48+
EVP_MD_CTX *EVP_MD_CTX_new(void);
49+
int EVP_MD_CTX_size(const EVP_MD_CTX *ctx);
50+
void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
51+
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
52+
int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
53+
int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
54+
int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
55+
int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
56+
int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen);
57+
58+
EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
59+
int EVP_CipherInit_ex(
60+
EVP_CIPHER_CTX *ctx,
61+
const EVP_CIPHER *cipher,
62+
ENGINE *impl,
63+
const unsigned char *key,
64+
const unsigned char *iv,
65+
int enc);
66+
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
67+
void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx);
68+
int EVP_EncryptInit_ex(
69+
EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, ENGINE *impl, const unsigned char *key, const unsigned char *iv);
70+
int EVP_DecryptInit_ex(
71+
EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, ENGINE *impl, const unsigned char *key, const unsigned char *iv);
72+
int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
73+
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
74+
int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
75+
int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
76+
int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
77+
78+
#define EVP_MD_CTX_create() EVP_MD_CTX_new()
79+
#define EVP_MD_CTX_destroy(ctx) EVP_MD_CTX_free((ctx))
80+
81+
const EVP_CIPHER *EVP_aes_128_gcm(void);
82+
const EVP_CIPHER *EVP_aes_192_gcm(void);
83+
const EVP_CIPHER *EVP_aes_256_gcm(void);
84+
const EVP_MD *EVP_sha256(void);
85+
const EVP_MD *EVP_sha384(void);
86+
const EVP_MD *EVP_sha512(void);
87+
88+
int EVP_MD_size(const EVP_MD *md);
89+
90+
#define EVP_CTRL_INIT 0x0
91+
#define EVP_CTRL_SET_KEY_LENGTH 0x1
92+
#define EVP_CTRL_GET_RC2_KEY_BITS 0x2
93+
#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
94+
#define EVP_CTRL_GET_RC5_ROUNDS 0x4
95+
#define EVP_CTRL_SET_RC5_ROUNDS 0x5
96+
#define EVP_CTRL_RAND_KEY 0x6
97+
#define EVP_CTRL_PBE_PRF_NID 0x7
98+
#define EVP_CTRL_COPY 0x8
99+
#define EVP_CTRL_AEAD_SET_IVLEN 0x9
100+
#define EVP_CTRL_AEAD_GET_TAG 0x10
101+
#define EVP_CTRL_AEAD_SET_TAG 0x11
102+
#define EVP_CTRL_AEAD_SET_IV_FIXED 0x12
103+
#define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN
104+
#define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
105+
#define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
106+
#define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED
107+
#define EVP_CTRL_GCM_IV_GEN 0x13
108+
#define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN
109+
#define EVP_CTRL_CCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
110+
#define EVP_CTRL_CCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
111+
#define EVP_CTRL_CCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED
112+
#define EVP_CTRL_CCM_SET_L 0x14
113+
#define EVP_CTRL_CCM_SET_MSGLEN 0x15
114+
115+
#define EVP_PKEY_OP_UNDEFINED 0
116+
#define EVP_PKEY_OP_PARAMGEN (1 << 1)
117+
#define EVP_PKEY_OP_KEYGEN (1 << 2)
118+
#define EVP_PKEY_OP_SIGN (1 << 3)
119+
#define EVP_PKEY_OP_VERIFY (1 << 4)
120+
#define EVP_PKEY_OP_VERIFYRECOVER (1 << 5)
121+
#define EVP_PKEY_OP_SIGNCTX (1 << 6)
122+
#define EVP_PKEY_OP_VERIFYCTX (1 << 7)
123+
#define EVP_PKEY_OP_ENCRYPT (1 << 8)
124+
#define EVP_PKEY_OP_DECRYPT (1 << 9)
125+
#define EVP_PKEY_OP_DERIVE (1 << 10)
126+
127+
#define EVP_PKEY_ALG_CTRL 0x1000
128+
129+
#endif

0 commit comments

Comments
 (0)