Skip to content

Commit

Permalink
prepare release v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
smuellerDD committed Dec 11, 2018
1 parent 706b5c5 commit baf71e2
Show file tree
Hide file tree
Showing 51 changed files with 8,080 additions and 176 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
@@ -1,3 +1,8 @@
Changes 0.4.2
- add helper convert_cipher_algo
- use specific initializations for static variables (some compilers cannot handle generic initializations)
- statically link JSON-C

Changes 0.4.1
* Addition of helper function to turn an MPI into a byte array

Expand Down
10 changes: 10 additions & 0 deletions LICENSE
Expand Up @@ -14,3 +14,13 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.


The following code has a different copyright and license. The license
is provided with the mentioned source code.

* parser/json-c/

Copyright (c) 2009-2012 Eric Haszlakiewicz
Copyright (c) 2004, 2005 Metaparadigm Pte Ltd

6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -35,11 +35,12 @@ LIBPATCH=$(shell cat $(PARSERDIR)/parser.h | grep define | grep PATCHLEVEL | awk
LIBVERSION := $(LIBMAJOR).$(LIBMINOR).$(LIBPATCH)

C_SRCS := $(wildcard $(PARSERDIR)/*.c)
C_SRCS += $(wildcard $(PARSERDIR)/json-c/*.c)
C_SRCS := $(filter-out $(wildcard backend*.c), $(C_SRCS))

INCLUDE_DIRS := $(PARSERDIR)
LIBRARY_DIRS :=
LIBRARIES := json-c
LIBRARIES :=

################## CONFIGURE BACKEND KCAPI ###################

Expand Down Expand Up @@ -91,6 +92,7 @@ endif
################## CONFIGURE BACKEND CommonCrypto ################

ifeq (commoncrypto,$(firstword $(MAKECMDGOALS)))
INCLUDE_DIRS += backend_interfaces/commoncrypto
C_SRCS += backends/backend_commoncrypto.c
endif

Expand Down Expand Up @@ -225,11 +227,13 @@ asm:
clean:
@- $(RM) $(NAME)
@- $(RM) $(wildcard $(PARSERDIR)/*.o)
@- $(RM) $(wildcard $(PARSERDIR)/json-c/*.o)
@- $(RM) $(wildcard backend_interfaces/pkcs11/*.o)
@- $(RM) $(wildcard backends/*.o)
@- $(RM) $(ASM)
@- $(RM) $(wildcard *.plist)
@- $(RM) $(wildcard *$(PARSERDIR)/*.plist)
@- $(RM) $(wildcard *$(PARSERDIR)/json-c/*.plist)
@- $(RM) $(wildcard backend_interfaces/pkcs11/*.plist)
@- $(RM) $(wildcard backends/*.plist)

Expand Down
34 changes: 1 addition & 33 deletions README.md
Expand Up @@ -97,39 +97,7 @@ Building
Prerequisite
------------

The ACVP parser uses the lightweight json-C library for the processing and
writing of JSON formatted data. The json-C code can be found at [1]. As this
library is lightweight and yet versatile (it works on Unix and Windows),
it was chosen as the fundamental JSON processor.

[1] https://github.com/json-c/json-c

Prerequisites on macOS
----------------------

The application works out of the box on macOS without any changes. Though
json-C must be installed. As I am currently unaware of json-C macOS packages
you need to perform the following steps

1. Get json-c: git clone https://github.com/json-c/json-c

2. Get the autotool set to configure and install json-c:

a. Install homebrew from https://brew.sh by invoking `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`

b. Install autoconf: `brew install autoconf`

c. Install automake: `brew install automake`

d. Install libtool: `brew install libtool`

3. Compile json-c: go into json-c directory and invoke `./configure`

4. `make`

5. `sudo make install`

Now you are ready to compile the ACVP Parser.
The ACVP parser requires the presence of the POSIX APIs.

Compiling
---------
Expand Down
14 changes: 11 additions & 3 deletions backends/backend_openssl.c
Expand Up @@ -76,9 +76,12 @@ static int openssl_cipher(uint64_t cipher, uint32_t keylen,
{
int ret = 0;
const EVP_CIPHER *l_type = NULL;
const char *algo;

CKINT(convert_cipher_algo(cipher, &algo));

logger(LOGGER_DEBUG, "Key size = %u\n", keylen);
logger(LOGGER_DEBUG, "Cipher = %lu\n", cipher);
logger(LOGGER_DEBUG, "Cipher = %s\n", algo);

switch (cipher) {
case ACVP_ECB:
Expand Down Expand Up @@ -288,16 +291,20 @@ static int openssl_cipher(uint64_t cipher, uint32_t keylen,

*type = l_type;

out:
return ret;
}

static int openssl_md_convert(uint64_t cipher, const EVP_MD **type)
{
int ret = 0;
const EVP_MD *l_type = NULL;
const char *algo;

logger(LOGGER_DEBUG, "SHA = %lu\n",
cipher & (ACVP_HASHMASK | ACVP_HMACMASK));
CKINT(convert_cipher_algo(cipher & (ACVP_HASHMASK | ACVP_HMACMASK),
&algo));

logger(LOGGER_DEBUG, "SHA = %s\n", algo);

switch (cipher & (ACVP_HASHMASK | ACVP_HMACMASK)) {
case ACVP_HMACSHA1:
Expand Down Expand Up @@ -327,6 +334,7 @@ static int openssl_md_convert(uint64_t cipher, const EVP_MD **type)

*type = l_type;

out:
return ret;
}

Expand Down
42 changes: 42 additions & 0 deletions parser/json-c/COPYING
@@ -0,0 +1,42 @@

Copyright (c) 2009-2012 Eric Haszlakiewicz

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

----------------------------------------------------------------

Copyright (c) 2004, 2005 Metaparadigm Pte Ltd

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
146 changes: 146 additions & 0 deletions parser/json-c/arraylist.c
@@ -0,0 +1,146 @@
/*
* $Id: arraylist.c,v 1.4 2006/01/26 02:16:28 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See COPYING for details.
*
*/

#include "config.h"

#include <limits.h>

#ifdef STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif /* STDC_HEADERS */

#if defined(HAVE_STRINGS_H) && !defined(_STRING_H) && !defined(__USE_BSD)
# include <strings.h>
#endif /* HAVE_STRINGS_H */

#ifndef SIZE_T_MAX
#if SIZEOF_SIZE_T == SIZEOF_INT
#define SIZE_T_MAX UINT_MAX
#elif SIZEOF_SIZE_T == SIZEOF_LONG
#define SIZE_T_MAX ULONG_MAX
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
#define SIZE_T_MAX ULLONG_MAX
#else
#error Unable to determine size of size_t
#endif
#endif

#include "arraylist.h"

struct array_list*
array_list_new(array_list_free_fn *free_fn)
{
struct array_list *arr;

arr = (struct array_list*)calloc(1, sizeof(struct array_list));
if(!arr) return NULL;
arr->size = ARRAY_LIST_DEFAULT_SIZE;
arr->length = 0;
arr->free_fn = free_fn;
if(!(arr->array = (void**)calloc(sizeof(void*), arr->size))) {
free(arr);
return NULL;
}
return arr;
}

extern void
array_list_free(struct array_list *arr)
{
size_t i;
for(i = 0; i < arr->length; i++)
if(arr->array[i]) arr->free_fn(arr->array[i]);
free(arr->array);
free(arr);
}

void*
array_list_get_idx(struct array_list *arr, size_t i)
{
if(i >= arr->length) return NULL;
return arr->array[i];
}

static int array_list_expand_internal(struct array_list *arr, size_t max)
{
void *t;
size_t new_size;

if(max < arr->size) return 0;
/* Avoid undefined behaviour on size_t overflow */
if( arr->size >= SIZE_T_MAX / 2 )
new_size = max;
else
{
new_size = arr->size << 1;
if (new_size < max)
new_size = max;
}
if (new_size > (~((size_t)0)) / sizeof(void*)) return -1;
if (!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1;
arr->array = (void**)t;
(void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
arr->size = new_size;
return 0;
}

int
array_list_put_idx(struct array_list *arr, size_t idx, void *data)
{
if (idx > SIZE_T_MAX - 1 ) return -1;
if(array_list_expand_internal(arr, idx+1)) return -1;
if(idx < arr->length && arr->array[idx])
arr->free_fn(arr->array[idx]);
arr->array[idx] = data;
if(arr->length <= idx) arr->length = idx + 1;
return 0;
}

int
array_list_add(struct array_list *arr, void *data)
{
return array_list_put_idx(arr, arr->length, data);
}

void
array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *))
{
qsort(arr->array, arr->length, sizeof(arr->array[0]), sort_fn);
}

void* array_list_bsearch(const void **key, struct array_list *arr,
int (*sort_fn)(const void *, const void *))
{
return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]),
sort_fn);
}

size_t
array_list_length(struct array_list *arr)
{
return arr->length;
}

int
array_list_del_idx( struct array_list *arr, size_t idx, size_t count )
{
size_t i, stop;

stop = idx + count;
if ( idx >= arr->length || stop > arr->length ) return -1;
for ( i = idx; i < stop; ++i ) {
if ( arr->array[i] ) arr->free_fn( arr->array[i] );
}
memmove( arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void*) );
arr->length -= count;
return 0;
}

0 comments on commit baf71e2

Please sign in to comment.