Line data Source code
1 : /** 2 : * The MIT License (MIT) 3 : * 4 : * Copyright (c) 2021 RSK Labs Ltd 5 : * 6 : * Permission is hereby granted, free of charge, to any person obtaining a copy 7 : * of this software and associated documentation files (the "Software"), to 8 : * deal in the Software without restriction, including without limitation the 9 : * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 : * sell copies of the Software, and to permit persons to whom the Software is 11 : * furnished to do so, subject to the following conditions: 12 : * 13 : * The above copyright notice and this permission notice shall be included in 14 : * all copies or substantial portions of the Software. 15 : * 16 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 : * IN THE SOFTWARE. 23 : */ 24 : 25 : /** 26 : * Taken from https://github.com/someone42/hardware-bitcoin-wallet @ 27 : * 102c300d994712484c3c028b215f90a6f99d6155 and adapted for use with 28 : * the powHSM HAL by RootstockLabs. LICENSE transcribed below. 29 : */ 30 : 31 : /* 32 : Copyright (c) 2011-2012 someone42 33 : All rights reserved. 34 : 35 : Redistribution and use in source and binary forms, with or without 36 : modification, are permitted provided that the following conditions are met: 37 : 38 : Redistributions of source code must retain the above copyright notice, 39 : this list of conditions and the following disclaimer. 40 : 41 : Redistributions in binary form must reproduce the above copyright notice, 42 : this list of conditions and the following disclaimer in the documentation 43 : and/or other materials provided with the distribution. 44 : 45 : THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 46 : AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 : ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 49 : LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 50 : CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 51 : SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 52 : INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 53 : CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 54 : ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 55 : POSSIBILITY OF SUCH DAMAGE. 56 : */ 57 : 58 : /** \file endian.c 59 : * 60 : * \brief Contains functions which perform endian-specific type conversion. 61 : * 62 : * This file is licensed as described by the file LICENCE. 63 : */ 64 : 65 : #include "endian.h" 66 : 67 : /** Write 32 bit unsigned integer into a byte array in big-endian format. 68 : * \param out The destination byte array. This must have space for at 69 : * least 4 bytes. 70 : * \param in The source integer. 71 : */ 72 64 : void write_uint32_be(uint8_t *out, uint32_t in) { 73 64 : out[0] = (uint8_t)(in >> 24); 74 64 : out[1] = (uint8_t)(in >> 16); 75 64 : out[2] = (uint8_t)(in >> 8); 76 64 : out[3] = (uint8_t)in; 77 64 : }