示例#1
1
文件: DES+NNT.cpp 项目: imace/nnt
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);
}
示例#2
0
文件: AudioBuffer.cpp 项目: imace/nnt
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;
            }
        }
    }
}
示例#3
0
文件: packages.cpp 项目: Botyto/Core
	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;
	}
示例#4
0
文件: AudioBuffer.cpp 项目: imace/nnt
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);
        }
    }
}
示例#5
0
文件: DES+NNT.cpp 项目: imace/nnt
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;
    }
}