Ejemplo n.º 1
1
void des::decrypt(char const* key, core::vector<byte> const& in, core::string& out)
{
    DES_cblock key_block;
    DES_key_schedule schedule;
    DES_string_to_key(key, &key_block);
    DES_set_key_checked(&key_block, &schedule);

    char* buf = (char*)malloc(in.size());

    core::vector<byte>::const_iterator iter = in.begin();
    DES_cblock* output = (DES_cblock*)buf;

    DES_cblock input;
    while (iter != in.end())
    {
        usize sz = in.end() - iter;
        if (sz >= 8)
            sz = 8;
        else
            memset(input, 0, sizeof(DES_cblock));
        memcpy(input, &*iter, sz);
        DES_ecb_encrypt(&input, output, &schedule, DES_DECRYPT);
        iter += sz;
        output += 1;
    }

    out = buf;

    free(buf);
}
Ejemplo n.º 2
0
void clear_buffers()
{
    if (d_owner->need_release && d_owner->queue)
    {
        for (core::vector<AudioQueueBufferRef>::iterator each = buffers.begin();
                each != buffers.end();
                ++each)
        {
            if (*each != NULL)
            {
                AudioQueueFreeBuffer(d_owner->queue, *each);
                *each = NULL;
            }
        }
    }
}
Ejemplo n.º 3
0
	bool output_pack(const core::string & packname, const core::vector<pack_entry> & entries)
	{
		//Final package output path
		string outpack = settings::packs_out + packname + "." + settings::extension;

		//Package writer
		fwriter writer(outpack, true);
		if (!writer.opened() || !writer.ok())
			return false;

		//Iterate entires
		writer.write_uint16((uint16_t)entries.size());
		for (auto e : entries)
		{
			console::print("[Packs] Packaging file (%) '%'", e.type, e.file);

			//Write file type
			writer.write_uint8((uint8_t)e.type);
			//Write file name size
			writer.write_uint8((uint8_t)e.file.size());
			//Write file name
			writer.write(e.file);

			string path = e.dir + e.file;

			//Write file size
			writer.write_uint32((uint32_t)io::size(path));
			//Write file contents
			if (!io::append_content(path, writer))
				return false;
		}

		writer.close();
		return true;
	}
Ejemplo n.º 4
0
void create_buffers()
{
    clear_buffers();

    usize sz = calc_buffer_size();

    OSStatus sta;
    for (core::vector<AudioQueueBufferRef>::iterator each = buffers.begin();
            each != buffers.end();
            ++each)
    {
        if ((sta = AudioQueueAllocateBuffer(d_owner->queue, sz, &*each)))
        {
            trace_fmt("failed to allocate audio buffer, %.4s", (char*)&sta);
        }
    }
}
Ejemplo n.º 5
0
NNT_BEGIN_HEADER_C

# include <openssl/des.h>
# include <math.h>

NNT_END_HEADER_C

NNT_BEGIN_CXX

void des::encrypt(char const* key, core::string const& in, core::vector<byte>& out)
{
    DES_cblock key_block;
    DES_key_schedule schedule;
    DES_string_to_key(key, &key_block);
    DES_set_key_checked(&key_block, &schedule);

    usize sz = (usize)ceil((double)in.size() / sizeof(DES_cblock)) * sizeof(DES_cblock);
    out.resize(sz);

    core::string::const_iterator iter = in.begin();
    DES_cblock* output = (DES_cblock*)core::pointer(out);

    DES_cblock input;
    while (iter != in.end())
    {
        usize sz = in.end() - iter;
        if (sz >= 8)
            sz = 8;
        else
            memset(input, 0, sizeof(DES_cblock));
        memcpy(input, &*iter, sz);
        DES_ecb_encrypt(&input, output, &schedule, DES_ENCRYPT);
        iter += sz;
        output += 1;
    }
}