kopia lustrzana https://github.com/weetmuts/wmbusmeters
Improve testing code coverage.
rodzic
8dd3e87c44
commit
f0677c2587
9
Makefile
9
Makefile
|
@ -268,10 +268,19 @@ clean_cc:
|
|||
find . -name "*.gcov" -delete
|
||||
find . -name "*.gcda" -delete
|
||||
|
||||
# This generates annotated source files ending in .gcov
|
||||
# inside the build_debug where non-executed source lines are marked #####
|
||||
gcov:
|
||||
@if [ "$(DEBUG)" = "" ]; then echo "You have to run \"make gcov DEBUG=true\""; exit 1; fi
|
||||
$(GCOV) -o build_debug $(METER_OBJS)
|
||||
mv *.gcov build_debug
|
||||
|
||||
lcov:
|
||||
@if [ "$(DEBUG)" = "" ]; then echo "You have to run \"make lcov DEBUG=true\""; exit 1; fi
|
||||
lcov --directory . -c --no-external --output-file build_debug/lcov.info
|
||||
(cd build_debug; genhtml lcov.info)
|
||||
xdg-open build_debug/src/index.html
|
||||
|
||||
test:
|
||||
@./test.sh build/wmbusmeters
|
||||
|
||||
|
|
12
src/aes.cc
12
src/aes.cc
|
@ -524,7 +524,7 @@ static void XorWithIv(uint8_t* buf)
|
|||
void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
||||
{
|
||||
uintptr_t i;
|
||||
uint8_t extra = length % BLOCKLEN; /* Remaining bytes in the last non-full block */
|
||||
// uint8_t extra = length % BLOCKLEN; /* Remaining bytes in the last non-full block */
|
||||
|
||||
// Skip the key expansion if key is passed as 0
|
||||
if (0 != key)
|
||||
|
@ -550,18 +550,18 @@ void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
|
|||
//printf("Step %d - %d", i/16, i);
|
||||
}
|
||||
|
||||
if (extra)
|
||||
/* if (extra)
|
||||
{
|
||||
memcpy(output, input, extra);
|
||||
state = (state_t*)output;
|
||||
Cipher();
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
||||
{
|
||||
uintptr_t i;
|
||||
uint8_t extra = length % BLOCKLEN; /* Remaining bytes in the last non-full block */
|
||||
// uint8_t extra = length % BLOCKLEN; /* Remaining bytes in the last non-full block */
|
||||
|
||||
// Skip the key expansion if key is passed as 0
|
||||
if (0 != key)
|
||||
|
@ -587,12 +587,12 @@ void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
|
|||
output += BLOCKLEN;
|
||||
}
|
||||
|
||||
if (extra)
|
||||
/* if (extra)
|
||||
{
|
||||
memcpy(output, input, extra);
|
||||
state = (state_t*)output;
|
||||
InvCipher();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
#endif // #if defined(CBC) && (CBC == 1)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include"aes.h"
|
||||
#include"aescmac.h"
|
||||
#include"cmdline.h"
|
||||
#include"config.h"
|
||||
|
@ -39,6 +40,7 @@ void test_periods();
|
|||
void test_devices();
|
||||
void test_meters();
|
||||
void test_months();
|
||||
void test_aes();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -66,6 +68,7 @@ int main(int argc, char **argv)
|
|||
test_kdf();
|
||||
test_periods();
|
||||
test_months();
|
||||
test_aes();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -803,3 +806,52 @@ void test_meters()
|
|||
"c1"); // linkmodes
|
||||
|
||||
}
|
||||
|
||||
void test_aes()
|
||||
{
|
||||
vector<uchar> key;
|
||||
|
||||
hex2bin("0123456789abcdef0123456789abcdef", &key);
|
||||
string poe =
|
||||
"Once upon a midnight dreary, while I pondered, weak and weary,\n"
|
||||
"Over many a quaint and curious volume of forgotten lore\n";
|
||||
|
||||
while (poe.length() % 16 != 0)
|
||||
{
|
||||
poe += ".";
|
||||
}
|
||||
|
||||
uchar iv[16];
|
||||
memset(iv, 0xaa, 16);
|
||||
|
||||
uchar in[poe.length()];
|
||||
memcpy(in, &poe[0], poe.size());
|
||||
|
||||
debug("(aes) input: \"%s\"\n", poe.c_str());
|
||||
|
||||
uchar out[sizeof(in)];
|
||||
AES_CBC_encrypt_buffer(out, in, sizeof(in), &key[0], iv);
|
||||
|
||||
vector<uchar> outv(out, out+sizeof(out));
|
||||
string s = bin2hex(outv);
|
||||
debug("(aes) encrypted: \"%s\"\n", s.c_str());
|
||||
|
||||
uchar back[sizeof(in)];
|
||||
AES_CBC_decrypt_buffer(back, out, sizeof(in), &key[0], iv);
|
||||
|
||||
string b = string(back, back+sizeof(back));
|
||||
debug("(aes) decrypted: \"%s\"\n", b.c_str());
|
||||
|
||||
if (poe != b)
|
||||
{
|
||||
printf("ERROR! aes with IV encrypt decrypt failed!\n");
|
||||
}
|
||||
|
||||
AES_ECB_encrypt(in, &key[0], out, sizeof(in));
|
||||
AES_ECB_decrypt(out, &key[0], back, sizeof(in));
|
||||
|
||||
if (memcmp(back, in, sizeof(in)))
|
||||
{
|
||||
printf("ERROR! aes encrypt decrypt (no iv) failed!\n");
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue