Skip to content

Commit

Permalink
Merge pull request #336 from raycoll/separate_init
Browse files Browse the repository at this point in the history
Move s2n_{init,cleanup} to separate source file
  • Loading branch information
colmmacc authored Nov 25, 2016
2 parents cc45641 + 7486f47 commit 0d5925b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
36 changes: 36 additions & 0 deletions utils/s2n_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include "tls/s2n_cipher_suites.h"

#include "utils/s2n_mem.h"
#include "utils/s2n_random.h"
#include "utils/s2n_safety.h"

int s2n_init(void)
{
GUARD(s2n_mem_init());
GUARD(s2n_rand_init());

return 0;
}

int s2n_cleanup(void)
{
GUARD(s2n_rand_cleanup());
GUARD(s2n_mem_cleanup());

return 0;
}
19 changes: 19 additions & 0 deletions utils/s2n_init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#pragma once

int s2n_init(void);
int s2n_cleanup(void);
7 changes: 7 additions & 0 deletions utils/s2n_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ int s2n_mem_init(void)
return 0;
}

int s2n_mem_cleanup(void)
{
page_size = 4096;
use_mlock = 1;
return 0;
}

int s2n_alloc(struct s2n_blob *b, uint32_t size)
{
b->data = NULL;
Expand Down
1 change: 1 addition & 0 deletions utils/s2n_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdint.h>

int s2n_mem_init(void);
int s2n_mem_cleanup(void);
int s2n_alloc(struct s2n_blob *b, uint32_t size);
int s2n_realloc(struct s2n_blob *b, uint32_t size);
int s2n_free(struct s2n_blob *b);
Expand Down
6 changes: 2 additions & 4 deletions utils/s2n_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,8 @@ RAND_METHOD s2n_openssl_rand_method = {
};
#endif

int s2n_init(void)
int s2n_rand_init(void)
{
GUARD(s2n_mem_init());

OPEN:
entropy_fd = open(ENTROPY_SOURCE, O_RDONLY);
if (entropy_fd == -1) {
Expand Down Expand Up @@ -277,7 +275,7 @@ int s2n_init(void)
return 0;
}

int s2n_cleanup(void)
int s2n_rand_cleanup(void)
{
if (entropy_fd == -1) {
S2N_ERROR(S2N_ERR_NOT_INITIALIZED);
Expand Down
2 changes: 2 additions & 0 deletions utils/s2n_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "utils/s2n_blob.h"

extern int s2n_rand_init(void);
extern int s2n_rand_cleanup(void);
extern int s2n_get_public_random_data(struct s2n_blob *blob);
extern int s2n_get_public_random_bytes_used(void);
extern int s2n_get_private_random_data(struct s2n_blob *blob);
Expand Down

0 comments on commit 0d5925b

Please sign in to comment.