--- /dev/null
+#include "ByteBuffer.h"
+#include <string.h>
+
+ByteBuffer::ByteBuffer(Array<char> *array) :
+ buffer(array),
+ offset(0) {
+}
+
+void ByteBuffer::put(char c) {
+ buffer->set(offset++ , c);
+}
+
+void ByteBuffer::putInt(int32_t l) {
+ buffer->set(offset++, (char)(l >> 24));
+ buffer->set(offset++, (char)((l >> 16) & 0xff));
+ buffer->set(offset++, (char)((l >> 8) & 0xff));
+ buffer->set(offset++, (char)(l & 0xff));
+}
+
+void ByteBuffer::putLong(int64_t l) {
+ buffer->set(offset++, (char)(l >> 56));
+ buffer->set(offset++, (char)((l >> 48) & 0xff));
+ buffer->set(offset++, (char)((l >> 40) & 0xff));
+ buffer->set(offset++, (char)((l >> 32) & 0xff));
+ buffer->set(offset++, (char)((l >> 24) & 0xff));
+ buffer->set(offset++, (char)((l >> 16) & 0xff));
+ buffer->set(offset++, (char)((l >> 8) & 0xff));
+ buffer->set(offset++, (char)(l & 0xff));
+}
+
+void ByteBuffer::put(Array<char> *array) {
+ memcpy(&buffer->internalArray()[offset], array->internalArray(), array->length());
+ offset+=array->length();
+}
+
+int64_t ByteBuffer::getLong() {
+ char * array = &buffer->internalArray()[offset];
+ offset+=8;
+ return (((int64_t)array[0]) << 56) |
+ (((int64_t)array[1]) << 48) |
+ (((int64_t)array[2]) << 40) |
+ (((int64_t)array[3]) << 32) |
+ (((int64_t)array[4]) << 24) |
+ (((int64_t)array[5]) << 16) |
+ (((int64_t)array[6]) << 8) |
+ (((int64_t)array[7]));
+}
+
+int32_t ByteBuffer::getInt() {
+ char * array = &buffer->internalArray()[offset];
+ offset+=4;
+ return (((int32_t)array[0]) << 24) |
+ (((int32_t)array[1]) << 16) |
+ (((int32_t)array[2]) << 8) |
+ (((int32_t)array[3]));
+}
+
+char ByteBuffer::get() {
+ return buffer->get(offset++);
+}
+
+void ByteBuffer::get(Array<char> *array) {
+ memcpy(array->internalArray(), &buffer->internalArray()[offset], array->length());
+ offset += array->length();
+}
+
+void ByteBuffer::position(int32_t newPosition) {
+ offset = newPosition;
+}
+
+Array<char> *ByteBuffer::array() {
+ return buffer;
+}
+
+ByteBuffer *ByteBuffer_wrap(Array<char> *array) {
+ return new ByteBuffer(array);
+}
+
+ByteBuffer *ByteBuffer_allocate(uint size) {
+ return new ByteBuffer(new Array<char>(size));
+}
--- /dev/null
+#include "Mac.h"
+#include "Crypto.h"
+
+Mac::Mac() {
+}
+
+void Mac::update(Array<char> *array, int32_t offset, int32_t len) {
+ sha2_hmac_update(&ctx, (const unsigned char *) &array->internalArray()[offset], len);
+}
+
+Array<char> * Mac::doFinal() {
+ Array<char> * hmac = new Array<char>(32);
+ sha2_hmac_finish(&ctx, (unsigned char *) hmac->internalArray());
+ return hmac;
+}
+
+void Mac::init(AESKey *key) {
+ sha2_hmac_starts(&ctx, (const unsigned char *) key->getKey()->internalArray(), key->getKey()->length(), false);
+}