Files
Bartosz Gotowalski 8e9ed532cc Linux 2.26 Open Source Gold Release
Intel® Software Guard Extensions (Intel® SGX) for Linux OS includes the following changes in version 2.26:
- Upgraded to OpenSSL 3.1.6.
- Removed support for the MbedTLS Trusted Library.
- Added support for Red Hat Enterprise Linux Server 9.4 (for x86_64) and SUSE Linux Enterprise Server 15.6 64-bits.
- Added support for the FIPS 140-3 Certifiable OpenSSL Provider as an experimental feature.
- Bug fixes.

Signed-off-by: Gotowalski, Bartosz <bartosz.gotowalski@intel.com>
2025-05-30 14:54:34 +02:00

147 lines
4.6 KiB
C++

/*
* Copyright (C) 2011-2021 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "util_st.h"
#include "se_trace.h"
#include "arch.h"
#include <assert.h>
#include <fstream>
#include <vector>
extern "C" bool write_data_to_file(const char *filename, std::ios_base::openmode mode,
uint8_t *buf, size_t bsize, long offset)
{
if(filename == NULL || (buf == NULL && bsize != 0) || (buf != NULL && bsize == 0))
return false;
std::ofstream ofs(filename, mode);
if(!ofs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, filename);
return false;
}
ofs.seekp(offset, std::ios::beg);
ofs.write(reinterpret_cast<char*>(buf), bsize);
if(ofs.fail())
{
se_trace(SE_TRACE_ERROR, WRITE_FILE_ERROR, filename);
return false;
}
return true;
}
extern "C" size_t get_file_size(const char *filename)
{
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
if(!ifs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, filename);
return -1;
}
ifs.seekg(0, std::ios::end);
size_t size = (size_t)ifs.tellg();
return size;
}
extern "C" bool read_file_to_buf(const char *filename, uint8_t *buf, size_t bsize)
{
if(filename == NULL || buf == NULL || bsize == 0)
return false;
std::ifstream ifs(filename, std::ios::binary|std::ios::in);
if(!ifs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, filename);
return false;
}
ifs.read(reinterpret_cast<char *> (buf), bsize);
if(ifs.fail())
{
return false;
}
return true;
}
extern "C" bool copy_file(const char *source_path, const char *dest_path)
{
std::ifstream ifs(source_path, std::ios::binary|std::ios::in);
if(!ifs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, source_path);
return false;
}
std::ofstream ofs(dest_path, std::ios::binary|std::ios::out);
if(!ofs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, dest_path);
return false;
}
ofs << ifs.rdbuf();
return true;
}
// Append data from the 'src file to the 'dst' file. It adds some 0 padding
// to ensure the start addr of the append content is page-aligned.
extern "C" bool append_file_with_padding(const char *dst, const char *src)
{
std::ifstream ifs(src, std::ios::binary|std::ios::in);
if(!ifs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, src);
return false;
}
std::ofstream ofs(dst, std::ios::binary|std::ios::app);
if(!ofs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, dst);
return false;
}
size_t size = (size_t)ofs.tellp();
size_t size_aligned = (size + SE_PAGE_SIZE - 1) & (~(SE_PAGE_SIZE - 1));
std::vector<char> buffer(size_aligned - size, 0);
ofs.write(buffer.data(), buffer.size());
ofs.close();
ofs.open(dst, std::ios::binary|std::ios::app);
if(!ofs.good())
{
se_trace(SE_TRACE_ERROR, OPEN_FILE_ERROR, dst);
return false;
}
ofs << ifs.rdbuf();
return true;
}