cyassl re-port with cellular comms, PSK test
Dependencies: VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src
cyassllib/ctaocrypt/src/memory.c@0:e979170e02e7, 2013-04-26 (annotated)
- Committer:
- ashleymills
- Date:
- Fri Apr 26 16:54:58 2013 +0000
- Revision:
- 0:e979170e02e7
Basic operation of SSL with PSK working for cellular.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:e979170e02e7 | 1 | /* memory.c |
ashleymills | 0:e979170e02e7 | 2 | * |
ashleymills | 0:e979170e02e7 | 3 | * Copyright (C) 2006-2012 Sawtooth Consulting Ltd. |
ashleymills | 0:e979170e02e7 | 4 | * |
ashleymills | 0:e979170e02e7 | 5 | * This file is part of CyaSSL. |
ashleymills | 0:e979170e02e7 | 6 | * |
ashleymills | 0:e979170e02e7 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
ashleymills | 0:e979170e02e7 | 8 | * it under the terms of the GNU General Public License as published by |
ashleymills | 0:e979170e02e7 | 9 | * the Free Software Foundation; either version 2 of the License, or |
ashleymills | 0:e979170e02e7 | 10 | * (at your option) any later version. |
ashleymills | 0:e979170e02e7 | 11 | * |
ashleymills | 0:e979170e02e7 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
ashleymills | 0:e979170e02e7 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ashleymills | 0:e979170e02e7 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ashleymills | 0:e979170e02e7 | 15 | * GNU General Public License for more details. |
ashleymills | 0:e979170e02e7 | 16 | * |
ashleymills | 0:e979170e02e7 | 17 | * You should have received a copy of the GNU General Public License |
ashleymills | 0:e979170e02e7 | 18 | * along with this program; if not, write to the Free Software |
ashleymills | 0:e979170e02e7 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
ashleymills | 0:e979170e02e7 | 20 | */ |
ashleymills | 0:e979170e02e7 | 21 | |
ashleymills | 0:e979170e02e7 | 22 | #ifdef HAVE_CONFIG_H |
ashleymills | 0:e979170e02e7 | 23 | #include <config.h> |
ashleymills | 0:e979170e02e7 | 24 | #endif |
ashleymills | 0:e979170e02e7 | 25 | |
ashleymills | 0:e979170e02e7 | 26 | /* submitted by eof */ |
ashleymills | 0:e979170e02e7 | 27 | |
ashleymills | 0:e979170e02e7 | 28 | |
ashleymills | 0:e979170e02e7 | 29 | #include <cyassl/ctaocrypt/settings.h> |
ashleymills | 0:e979170e02e7 | 30 | |
ashleymills | 0:e979170e02e7 | 31 | #ifdef USE_CYASSL_MEMORY |
ashleymills | 0:e979170e02e7 | 32 | |
ashleymills | 0:e979170e02e7 | 33 | #include <cyassl/ctaocrypt/memory.h> |
ashleymills | 0:e979170e02e7 | 34 | #include <cyassl/ctaocrypt/error.h> |
ashleymills | 0:e979170e02e7 | 35 | |
ashleymills | 0:e979170e02e7 | 36 | |
ashleymills | 0:e979170e02e7 | 37 | /* Set these to default values initially. */ |
ashleymills | 0:e979170e02e7 | 38 | static CyaSSL_Malloc_cb malloc_function = 0; |
ashleymills | 0:e979170e02e7 | 39 | static CyaSSL_Free_cb free_function = 0; |
ashleymills | 0:e979170e02e7 | 40 | static CyaSSL_Realloc_cb realloc_function = 0; |
ashleymills | 0:e979170e02e7 | 41 | |
ashleymills | 0:e979170e02e7 | 42 | int CyaSSL_SetAllocators(CyaSSL_Malloc_cb mf, |
ashleymills | 0:e979170e02e7 | 43 | CyaSSL_Free_cb ff, |
ashleymills | 0:e979170e02e7 | 44 | CyaSSL_Realloc_cb rf) |
ashleymills | 0:e979170e02e7 | 45 | { |
ashleymills | 0:e979170e02e7 | 46 | int res = 0; |
ashleymills | 0:e979170e02e7 | 47 | |
ashleymills | 0:e979170e02e7 | 48 | if (mf) |
ashleymills | 0:e979170e02e7 | 49 | malloc_function = mf; |
ashleymills | 0:e979170e02e7 | 50 | else |
ashleymills | 0:e979170e02e7 | 51 | res = BAD_FUNC_ARG; |
ashleymills | 0:e979170e02e7 | 52 | |
ashleymills | 0:e979170e02e7 | 53 | if (ff) |
ashleymills | 0:e979170e02e7 | 54 | free_function = ff; |
ashleymills | 0:e979170e02e7 | 55 | else |
ashleymills | 0:e979170e02e7 | 56 | res = BAD_FUNC_ARG; |
ashleymills | 0:e979170e02e7 | 57 | |
ashleymills | 0:e979170e02e7 | 58 | if (rf) |
ashleymills | 0:e979170e02e7 | 59 | realloc_function = rf; |
ashleymills | 0:e979170e02e7 | 60 | else |
ashleymills | 0:e979170e02e7 | 61 | res = BAD_FUNC_ARG; |
ashleymills | 0:e979170e02e7 | 62 | |
ashleymills | 0:e979170e02e7 | 63 | return res; |
ashleymills | 0:e979170e02e7 | 64 | } |
ashleymills | 0:e979170e02e7 | 65 | |
ashleymills | 0:e979170e02e7 | 66 | |
ashleymills | 0:e979170e02e7 | 67 | void* CyaSSL_Malloc(size_t size) |
ashleymills | 0:e979170e02e7 | 68 | { |
ashleymills | 0:e979170e02e7 | 69 | void* res = 0; |
ashleymills | 0:e979170e02e7 | 70 | |
ashleymills | 0:e979170e02e7 | 71 | if (malloc_function) |
ashleymills | 0:e979170e02e7 | 72 | res = malloc_function(size); |
ashleymills | 0:e979170e02e7 | 73 | else |
ashleymills | 0:e979170e02e7 | 74 | res = malloc(size); |
ashleymills | 0:e979170e02e7 | 75 | |
ashleymills | 0:e979170e02e7 | 76 | return res; |
ashleymills | 0:e979170e02e7 | 77 | } |
ashleymills | 0:e979170e02e7 | 78 | |
ashleymills | 0:e979170e02e7 | 79 | void CyaSSL_Free(void *ptr) |
ashleymills | 0:e979170e02e7 | 80 | { |
ashleymills | 0:e979170e02e7 | 81 | if (free_function) |
ashleymills | 0:e979170e02e7 | 82 | free_function(ptr); |
ashleymills | 0:e979170e02e7 | 83 | else |
ashleymills | 0:e979170e02e7 | 84 | free(ptr); |
ashleymills | 0:e979170e02e7 | 85 | } |
ashleymills | 0:e979170e02e7 | 86 | |
ashleymills | 0:e979170e02e7 | 87 | void* CyaSSL_Realloc(void *ptr, size_t size) |
ashleymills | 0:e979170e02e7 | 88 | { |
ashleymills | 0:e979170e02e7 | 89 | void* res = 0; |
ashleymills | 0:e979170e02e7 | 90 | |
ashleymills | 0:e979170e02e7 | 91 | if (realloc_function) |
ashleymills | 0:e979170e02e7 | 92 | res = realloc_function(ptr, size); |
ashleymills | 0:e979170e02e7 | 93 | else |
ashleymills | 0:e979170e02e7 | 94 | res = realloc(ptr, size); |
ashleymills | 0:e979170e02e7 | 95 | |
ashleymills | 0:e979170e02e7 | 96 | return res; |
ashleymills | 0:e979170e02e7 | 97 | } |
ashleymills | 0:e979170e02e7 | 98 | |
ashleymills | 0:e979170e02e7 | 99 | #endif /* USE_CYASSL_MEMORY */ |