Skip to content

Commit

Permalink
acvp: handle flush commond in modulewrapper as stated in BoringSSL.
Browse files Browse the repository at this point in the history
Change-Id: Ife655f0764851cf2d9677abd507daec3f531031e
Bug: 287626912
Test: ACVP test
  • Loading branch information
Yurii Shutkin committed Oct 9, 2023
1 parent af5de39 commit f75464d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions trusty/utils/acvp/trusty_modulewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
#include <android-base/result.h>
#include <android-base/unique_fd.h>
#include <errno.h>
#include <iostream>
#include <log/log.h>
#include <modulewrapper.h>
#include <openssl/span.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <trusty/tipc.h>
#include <unistd.h>
#include <iostream>

#include "acvp_ipc.h"

Expand Down Expand Up @@ -208,6 +209,11 @@ Result<void> ModuleWrapper::ForwardResponse() {
return {};
}

static bool EqString(bssl::Span<const uint8_t> cmd, const char *str) {
return cmd.size() == strlen(str) &&
memcmp(str, cmd.data(), cmd.size()) == 0;
}

int main() {
for (;;) {
auto buffer = bssl::acvp::RequestBuffer::New();
Expand All @@ -217,17 +223,24 @@ int main() {
return EXIT_FAILURE;
}

ModuleWrapper wrapper;
auto res = wrapper.SendMessage(args);
if (!res.ok()) {
std::cerr << res.error() << std::endl;
return EXIT_FAILURE;
}
if (EqString(args[0], "flush")) {
if (!bssl::acvp::FlushBuffer(STDOUT_FILENO)) {
ALOGE("Could not flush the buffer to stdout\n");
return EXIT_FAILURE;
}
} else {
ModuleWrapper wrapper;
auto res = wrapper.SendMessage(args);
if (!res.ok()) {
std::cerr << res.error() << std::endl;
return EXIT_FAILURE;
}

res = wrapper.ForwardResponse();
if (!res.ok()) {
std::cerr << res.error() << std::endl;
return EXIT_FAILURE;
res = wrapper.ForwardResponse();
if (!res.ok()) {
std::cerr << res.error() << std::endl;
return EXIT_FAILURE;
}
}
}

Expand Down

0 comments on commit f75464d

Please sign in to comment.