A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

sbtools: convert crypto to libtomcrypt.

Replace the use of crypto++ with tomcrypt, which is much smaller and C.
This gets rid of various build issues for systems that don't ship
crypo++ (i.e. everything except Linux.)

Change-Id: Ic0799e17b94935c71b14765cf9a2a7ea2b0adc7a

+50 -64
+18 -15
rbutil/mkimxboot/Makefile
··· 8 8 # We use the SB code available in the Rockbox utils/sbtools directory 9 9 10 10 IMXTOOLS_DIR=../../utils/imxtools/sbtools/ 11 - CFLAGS += -I$(IMXTOOLS_DIR) -Wall 11 + 12 + COMPILEFLAGS := -Wall -g -O3 -I$(IMXTOOLS_DIR) 13 + 12 14 # std=gnu99 is required by MinGW on Windows (c99 is sufficient for Linux / MXE) 13 - CFLAGS += -std=gnu99 -g -O3 15 + CFLAGS += -std=gnu99 $(COMPILEFLAGS) 16 + CXXFLAGS += $(COMPILEFLAGS) 14 17 15 - # Location to pkg-config binary. 16 - PKGCONFIG := pkg-config 18 + TOMCRYPT_DIR := ../../utils/tomcrypt 17 19 18 - # Distros could use different names for the crypto library. We try a list 19 - # of candidate names, only one of them should be the valid one. 20 - LIBCRYPTO_NAMES = libcryptopp libcrypto++ cryptopp crypto++ 21 - 22 - $(foreach l,$(LIBCRYPTO_NAMES),\ 23 - $(eval LDOPTS += $(shell $(PKGCONFIG) --silence-errors --libs $(l)))) 24 - $(foreach l,$(LIBCRYPTO_NAMES),\ 25 - $(eval CFLAGS += $(shell $(PKGCONFIG) --silence-errors --cflags $(l)))) 26 - $(foreach l,$(LIBCRYPTO_NAMES),\ 27 - $(eval CXXFLAGS += $(shell $(PKGCONFIG) --silence-errors --cflags $(l)))) 28 - LDOPTS += -lpthread 20 + CXXFLAGS += -I$(TOMCRYPT_DIR)/src/headers 21 + CFLAGS += -I$(TOMCRYPT_DIR)/src/headers 22 + LDOPTS += -lpthread $(TOMCRYPT_DIR)/librbtomcrypt.a 29 23 30 24 OUTPUT = mkimxboot 31 25 ··· 33 27 IMXTOOLS_SOURCES = misc.c sb.c crypto.cpp crc.c elf.c 34 28 LIBSOURCES := dualboot.c mkimxboot.c md5.c \ 35 29 $(addprefix $(IMXTOOLS_DIR),$(IMXTOOLS_SOURCES)) 30 + 31 + # for now build tomcrypt as part of the lib. 32 + LIBSOURCES += $(addprefix $(TOMCRYPT_DIR),$(TOMCRYPT_SOURCES)) 33 + 36 34 # inputs for binary only 37 35 SOURCES := $(LIBSOURCES) main.c 38 36 # dependencies for binary ··· 43 41 # explicit dependencies on dualboot.{c,h} and mkimxboot.h 44 42 $(OBJDIR)mkimxboot.o: dualboot.h dualboot.c mkimxboot.c mkimxboot.h 45 43 $(OBJDIR)main.o: dualboot.h dualboot.c main.c mkimxboot.h 44 + $(BINARY): librbtomcrypt.a 45 + 46 + librbtomcrypt.a: 47 + $(MAKE) -C ../../utils/tomcrypt 48 +
+3 -1
rbutil/rbutilqt/Makefile.libs
··· 33 33 export CXX=$(EXTRALIBS_CXX) 34 34 export AR=$(EXTRALIBS_AR) 35 35 36 - libs: librbspeex libucl libipodpatcher libsansapatcher libmkamsboot libmktccboot libmkmpioboot libchinachippatcher libmkimxboot libmks5lboot libbzip2 libbspatch 36 + libs: librbspeex libucl libipodpatcher libsansapatcher libmkamsboot libmktccboot libmkmpioboot libchinachippatcher libmkimxboot libmks5lboot libbzip2 libbspatch librbtomcrypt 37 37 38 38 # To support cross compiles, we explicitly pass the CC flag below for 39 39 # all tools which override CC or CXX in their makefiles. CXX is only 40 40 # used by mkimxboot. 41 41 42 + librbtomcrypt: 43 + $(SILENT) $(MAKE) -C $(RBBASE_DIR)/utils/tomcrypt BUILD_DIR=$(BUILD_DIR)/tomcrypt librbtomcrypt.a 42 44 librbspeex: 43 45 $(SILENT) $(MAKE) -C $(RBBASE_DIR)/tools/rbspeex BUILD_DIR=$(BUILD_DIR)/libspeex librbspeex.a 44 46
+2 -4
rbutil/rbutilqt/rbutilqt.pro
··· 85 85 # Note: order is important for RBLIBS! The libs are appended to the linker 86 86 # flags in this order, put libucl at the end. 87 87 RBLIBS = rbspeex ipodpatcher sansapatcher mkamsboot mktccboot \ 88 - mkmpioboot chinachippatcher mkimxboot mks5lboot bspatch ucl 88 + mkmpioboot chinachippatcher mkimxboot mks5lboot bspatch ucl \ 89 + rbtomcrypt 89 90 # NOTE: Linking bzip2 causes problems on Windows (Qt seems to export those 90 91 # symbols as well, similar to what we have with zlib.) Only link that on 91 92 # non-Windows for now. ··· 138 139 for(rblib, RBLIBS) { 139 140 LIBS += -l$$rblib 140 141 } 141 - 142 - # We need libcrypto++ 143 - LIBS += -lcryptopp 144 142 145 143 # on win32 libz is linked implicitly. 146 144 !win32 {
+11 -6
utils/imxtools/sbtools/Makefile
··· 3 3 CXX := g++ 4 4 LD := g++ 5 5 6 - LIBUSB := $(shell pkg-config --cflags libusb-1.0) 7 - CFLAGS := -O3 -g -std=c99 -Wall $(shell pkg-config --cflags libusb-1.0) $(DEFINES) 8 - CXXFLAGS := -O3 -g -Wall $(pkg-config --cflags libcrypto++) $(DEFINES) 9 - LDFLAGS := $(shell pkg-config --libs libusb-1.0) $(shell pkg-config --libs libcrypto++) 6 + TOMCRYPT_DIR := ../../tomcrypt/ 7 + 8 + CFLAGS := -O3 -g -std=c99 -Wall $(shell pkg-config --cflags libusb-1.0) $(DEFINES) -I$(TOMCRYPT_DIR)/src/headers 9 + CXXFLAGS := -O3 -g -Wall $(DEFINES) -I$(TOMCRYPT_DIR)/src/headers 10 + LDFLAGS := $(shell pkg-config --libs libusb-1.0) 10 11 BINS := elftosb sbtoelf sbloader rsrctool elftosb1 11 12 12 13 all: $(BINS) ··· 17 18 %.o: %.cpp 18 19 $(CXX) $(CXXFLAGS) -c -o $@ $< 19 20 20 - sbtoelf: sbtoelf.o crc.o crypto.o xorcrypt.o dbparser.o elf.o misc.o sb.o sb1.o 21 + sbtoelf: sbtoelf.o crc.o crypto.o xorcrypt.o dbparser.o elf.o misc.o sb.o sb1.o $(TOMCRYPT_DIR)/librbtomcrypt.a 21 22 $(LD) -o $@ $^ $(LDFLAGS) 22 23 23 - elftosb: elftosb.o crc.o crypto.o elf.o dbparser.o misc.o sb.o 24 + elftosb: elftosb.o crc.o crypto.o elf.o dbparser.o misc.o sb.o $(TOMCRYPT_DIR)/librbtomcrypt.a 24 25 $(LD) -o $@ $^ $(LDFLAGS) 25 26 26 27 elftosb1: elftosb1.o xorcrypt.o elf.o misc.o sb1.o ··· 37 38 38 39 veryclean: 39 40 rm -rf $(BINS) 41 + 42 + $(TOMCRYPT_DIR)/librbtomcrypt.a: 43 + $(MAKE) -C $(TOMCRYPT_DIR) 44 +
+14 -37
utils/imxtools/sbtools/crypto.cpp
··· 20 20 ****************************************************************************/ 21 21 #include "crypto.h" 22 22 #include "misc.h" 23 - #include <cryptopp/modes.h> 24 - #include <cryptopp/aes.h> 25 - #include <cryptopp/sha.h> 23 + 24 + #include "tomcrypt.h" 26 25 27 - using namespace CryptoPP; 28 26 29 - namespace 30 - { 31 27 32 28 enum crypto_method_t g_cur_method = CRYPTO_NONE; 33 29 uint8_t g_key[16]; 34 - CBC_Mode<AES>::Encryption g_aes_enc; 35 - CBC_Mode<AES>::Decryption g_aes_dec; 36 - bool g_aes_enc_key_dirty; /* true of g_aes_enc key needs to be updated */ 37 - bool g_aes_dec_key_dirty; /* same for g_aes_dec */ 38 30 39 31 int cbc_mac2( 40 32 const uint8_t *in_data, /* Input data */ ··· 46 38 bool encrypt /* 1 to encrypt, 0 to decrypt */ 47 39 ) 48 40 { 41 + int cipher = register_cipher(&aes_desc); 42 + symmetric_CBC cbc; 43 + cbc_start(cipher, iv, key, 16, 0, &cbc); 44 + 49 45 /* encrypt */ 50 46 if(encrypt) 51 47 { 52 - /* update keys if neeeded */ 53 - if(g_aes_enc_key_dirty) 54 - { 55 - /* we need to provide an IV with the key, although we change it 56 - * everytime we run the cipher anyway */ 57 - g_aes_enc.SetKeyWithIV(g_key, 16, iv, 16); 58 - g_aes_enc_key_dirty = false; 59 - } 60 - g_aes_enc.Resynchronize(iv, 16); 61 48 uint8_t tmp[16]; 62 49 /* we need some output buffer, either a temporary one if we are CBC-MACing 63 50 * only, or use output buffer if available */ 64 51 uint8_t *out_ptr = (out_data == NULL) ? tmp : out_data; 65 52 while(nr_blocks-- > 0) 66 53 { 67 - g_aes_enc.ProcessData(out_ptr, in_data, 16); 54 + cbc_encrypt(in_data, out_ptr, 16, &cbc); 68 55 /* if this is the last block, copy CBC-MAC */ 69 56 if(nr_blocks == 0 && out_cbc_mac) 70 57 memcpy(out_cbc_mac, out_ptr, 16); ··· 78 65 /* decrypt */ 79 66 else 80 67 { 68 + cbc_decrypt(in_data, out_data, nr_blocks * 16, &cbc); 69 + 81 70 /* update keys if neeeded */ 82 - if(g_aes_dec_key_dirty) 83 - { 84 - /* we need to provide an IV with the key, although we change it 85 - * everytime we run the cipher anyway */ 86 - g_aes_dec.SetKeyWithIV(g_key, 16, iv, 16); 87 - g_aes_dec_key_dirty = false; 88 - } 89 71 /* we cannot produce a CBC-MAC in decrypt mode, output buffer exists */ 90 72 if(out_cbc_mac || out_data == NULL) 91 73 return CRYPTO_ERROR_INVALID_OP; 92 - g_aes_dec.Resynchronize(iv, 16); 93 - g_aes_dec.ProcessData(out_data, in_data, nr_blocks * 16); 74 + 94 75 return CRYPTO_ERROR_SUCCESS; 95 76 } 96 77 } 97 78 98 - } 99 79 100 80 int crypto_setup(struct crypto_key_t *key) 101 81 { ··· 104 84 { 105 85 case CRYPTO_KEY: 106 86 memcpy(g_key, key->u.key, 16); 107 - g_aes_dec_key_dirty = true; 108 - g_aes_enc_key_dirty = true; 87 + 109 88 return CRYPTO_ERROR_SUCCESS; 110 89 default: 111 90 return CRYPTO_ERROR_BADSETUP; ··· 128 107 129 108 void sha_1_init(struct sha_1_params_t *params) 130 109 { 131 - params->object = new SHA1; 110 + sha1_init(&params->state); 132 111 } 133 112 134 113 void sha_1_update(struct sha_1_params_t *params, uint8_t *buffer, int size) 135 114 { 136 - reinterpret_cast<SHA1 *>(params->object)->Update(buffer, size); 115 + sha1_process(&params->state, buffer, size); 137 116 } 138 117 139 118 void sha_1_finish(struct sha_1_params_t *params) 140 119 { 141 - SHA1 *obj = reinterpret_cast<SHA1 *>(params->object); 142 - obj->Final(params->hash); 143 - delete obj; 120 + sha1_done(&params->state, params->hash); 144 121 } 145 122 146 123 void sha_1_output(struct sha_1_params_t *params, uint8_t *out)
+2 -1
utils/imxtools/sbtools/crypto.h
··· 77 77 uint32_t crc(uint8_t *data, int size); 78 78 uint32_t crc_continue(uint32_t previous_crc, uint8_t *data, int size); 79 79 80 + #include "tomcrypt.h" 80 81 /* sha1.c */ 81 82 struct sha_1_params_t 82 83 { 83 84 uint8_t hash[20]; /* final hash */ 84 - void *object; /* pointer to CryptoPP::SHA1 object */ 85 + hash_state state; /* libtomcrypt state */ 85 86 }; 86 87 87 88 void sha_1_init(struct sha_1_params_t *params);