Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/crypto/crypto-misc.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* mbed Microcontroller Library |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2015-2016 Nuvoton |
sahilmgandhi | 18:6a4db94011d3 | 3 | * |
sahilmgandhi | 18:6a4db94011d3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sahilmgandhi | 18:6a4db94011d3 | 5 | * you may not use this file except in compliance with the License. |
sahilmgandhi | 18:6a4db94011d3 | 6 | * You may obtain a copy of the License at |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Unless required by applicable law or agreed to in writing, software |
sahilmgandhi | 18:6a4db94011d3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sahilmgandhi | 18:6a4db94011d3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sahilmgandhi | 18:6a4db94011d3 | 13 | * See the License for the specific language governing permissions and |
sahilmgandhi | 18:6a4db94011d3 | 14 | * limitations under the License. |
sahilmgandhi | 18:6a4db94011d3 | 15 | */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | |
sahilmgandhi | 18:6a4db94011d3 | 17 | |
sahilmgandhi | 18:6a4db94011d3 | 18 | #include "cmsis.h" |
sahilmgandhi | 18:6a4db94011d3 | 19 | #include "mbed_assert.h" |
sahilmgandhi | 18:6a4db94011d3 | 20 | #include "nu_modutil.h" |
sahilmgandhi | 18:6a4db94011d3 | 21 | #include "nu_bitutil.h" |
sahilmgandhi | 18:6a4db94011d3 | 22 | #include "crypto-misc.h" |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | static int crypto_inited = 0; |
sahilmgandhi | 18:6a4db94011d3 | 25 | static int crypto_sha_avail = 1; |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | void crypto_init(void) |
sahilmgandhi | 18:6a4db94011d3 | 28 | { |
sahilmgandhi | 18:6a4db94011d3 | 29 | if (crypto_inited) { |
sahilmgandhi | 18:6a4db94011d3 | 30 | return; |
sahilmgandhi | 18:6a4db94011d3 | 31 | } |
sahilmgandhi | 18:6a4db94011d3 | 32 | crypto_inited = 1; |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | CLK_EnableModuleClock(CRPT_MODULE); |
sahilmgandhi | 18:6a4db94011d3 | 35 | } |
sahilmgandhi | 18:6a4db94011d3 | 36 | |
sahilmgandhi | 18:6a4db94011d3 | 37 | /* Implementation that should never be optimized out by the compiler */ |
sahilmgandhi | 18:6a4db94011d3 | 38 | void crypto_zeroize(void *v, size_t n) |
sahilmgandhi | 18:6a4db94011d3 | 39 | { |
sahilmgandhi | 18:6a4db94011d3 | 40 | volatile unsigned char *p = (unsigned char*) v; |
sahilmgandhi | 18:6a4db94011d3 | 41 | while (n--) { |
sahilmgandhi | 18:6a4db94011d3 | 42 | *p++ = 0; |
sahilmgandhi | 18:6a4db94011d3 | 43 | } |
sahilmgandhi | 18:6a4db94011d3 | 44 | } |
sahilmgandhi | 18:6a4db94011d3 | 45 | |
sahilmgandhi | 18:6a4db94011d3 | 46 | int crypto_sha_acquire(void) |
sahilmgandhi | 18:6a4db94011d3 | 47 | { |
sahilmgandhi | 18:6a4db94011d3 | 48 | if (crypto_sha_avail) { |
sahilmgandhi | 18:6a4db94011d3 | 49 | crypto_sha_avail = 0; |
sahilmgandhi | 18:6a4db94011d3 | 50 | return 1; |
sahilmgandhi | 18:6a4db94011d3 | 51 | } |
sahilmgandhi | 18:6a4db94011d3 | 52 | else { |
sahilmgandhi | 18:6a4db94011d3 | 53 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 54 | } |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | } |
sahilmgandhi | 18:6a4db94011d3 | 57 | |
sahilmgandhi | 18:6a4db94011d3 | 58 | void crypto_sha_release(void) |
sahilmgandhi | 18:6a4db94011d3 | 59 | { |
sahilmgandhi | 18:6a4db94011d3 | 60 | if (! crypto_sha_avail) { |
sahilmgandhi | 18:6a4db94011d3 | 61 | crypto_sha_avail = 1; |
sahilmgandhi | 18:6a4db94011d3 | 62 | } |
sahilmgandhi | 18:6a4db94011d3 | 63 | } |