/** * Selects the attribute name. * * @param p0 the break flag * @param p1 the current position (Hand over as reference!) * @param p2 the remaining count */ void select_xml_attribute_name(void* p0, void* p1, void* p2) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Select xml attribute name."); // The comparison result. int r = *NUMBER_0_INTEGER_MEMORY_MODEL; if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { detect_array((void*) &r, p1, p2, (void*) ATTRIBUTE_VALUE_BEGIN_XML_NAME, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) ATTRIBUTE_VALUE_BEGIN_XML_NAME_COUNT, (void*) NUMBER_1_INTEGER_MEMORY_MODEL); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { // The attribute name end was found. // // CAUTION! The current position and remaining count were already // changed in the called function, to be processed further. // // The attribute count is left as it is. // Set break flag. copy_integer(p0, (void*) NUMBER_1_INTEGER_MEMORY_MODEL); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { move_position(p1, p2, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_INTEGRAL_TYPE_SIZE); } }
unsigned int integer_to_binary(unsigned char** result,integer data,int keyLenBytes){ integer base=string_to_integer("256"); integer div=create_integer(data.num_components); copy_integer(data,div); integer zero=create_integer(1); zero.c[0]=0; unsigned char* pf=new unsigned char[data.num_components]; for(int i=0; i<data.num_components; i++){ pf[i]=0; } int tpos=data.num_components-1; pf[tpos]=div.c[0]; tpos--; while(compare_integers(div,zero)==1){ integer mod=create_integer(div.num_components+1+1); mod_integer(div,base,mod); integer div_temp=create_integer(div.num_components); copy_integer(div,div_temp); divide_small_integer(div_temp,256,div); pf[tpos]=div.c[0]; tpos--; } int startpos=div.num_components-keyLenBytes; *result=new unsigned char[keyLenBytes]; for(int i=0; i<keyLenBytes; i++){ (*result)[i]=pf[i+startpos]; } return keyLenBytes; }
int problem263() { integer testnum = string_to_integer("5"); integer testnum_helper = string_to_integer("5"); integer two = string_to_integer("2"); integer total_src = string_to_integer("0"); integer total_tar = string_to_integer("0"); integer target_dif = string_to_integer("6"); integer dif = string_to_integer("0"); int found = 0; integer lastprime = string_to_integer("5"); //int sexy_count = 0; printf("text here\n"); while (found < 4) { //printf("gets 1\n"); if (miller_rabin(testnum) == PRIME) { subtract_integer(testnum, lastprime, dif); if (compare_integers(dif, target_dif) == 0) { printf("difference between %s and %s is six\n", integer_to_string(testnum), integer_to_string(lastprime)); found++; }else { found = 1; } copy_integer(testnum, lastprime); add_integer(total_src, testnum, total_tar); copy_integer(total_tar, total_src); printf("Total is %s\n", integer_to_string(total_tar)); } add_integer(testnum_helper, two, testnum); copy_integer(testnum, testnum_helper); printf("Tested %s\n", integer_to_string(testnum)); } return 0; }
integer hex_to_integer(unsigned char* data, unsigned int datalenBytes, unsigned int pad){ integer base=string_to_integer("256"); int siz=datalenBytes; integer radix=create_integer(siz); set_zero_integer(radix); radix.c[0]=1; integer result=create_integer(siz*2+pad); set_zero_integer(result); integer digit=create_integer(1); for(int i=datalenBytes-1; i>=0; i--){ digit.c[0]=data[i]; integer part_res=create_integer(1+radix.num_components+1); set_zero_integer(part_res); multiply_integer(digit,radix,part_res); add_integer(result,part_res,result); free_integer(part_res); integer radix_temp=create_integer(radix.num_components); copy_integer(radix,radix_temp); multiply_integer(radix_temp,base,radix); free_integer(radix_temp); } optimize_integer(result); return result; }
/** * Checks input channels for interrupt requests. * * Example input channels: * - signal memory * - gnu/linux console * - x window system * - socket * * The "handler" is an operation encapsulated as part, which is * to be forwarded as signal to be processed normally in the system. * * @param p0 the interrupt request (Hand over as reference!) * @param p1 the mutex (Hand over as reference!) * @param p2 the handler (Hand over as reference!) * @param p3 the internal memory array */ void check_interrupt(void* p0, void* p1, void* p2, void* p3) { if (p0 != *NULL_POINTER_MEMORY_MODEL) { void** irq = (void**) p0; log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Check for interrupt requests."); // The internal memory index. int i = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // CAUTION! The boolean logic expression is necessary, because: // - first case: irq is null which means that NO OTHER irq has been checked before // - second case: irq is not null which means some other irq has been retrieved from // internal memory and checked before, BUT its value is zero anyway (irq not set) // // In both cases, this interrupt is retrieved and checked. // Otherwise, if an irq was retrieved AND its value is not zero (irq is set), // this and further interrupts are NOT checked. if ((*irq == *NULL_POINTER_MEMORY_MODEL) || ((*irq != *NULL_POINTER_MEMORY_MODEL) && (*((int*) *irq) == *NUMBER_0_INTEGER_MEMORY_MODEL))) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Detected signal memory interrupt."); // Get signal memory interrupt request. copy_array_forward(p0, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) SIGNAL_MEMORY_INTERRUPT_REQUEST_INTERNAL_MEMORY_MEMORY_NAME); // Get signal memory mutex. copy_array_forward(p1, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) SIGNAL_MEMORY_MUTEX_INTERNAL_MEMORY_MEMORY_NAME); // A handler is NOT set in the case of a signal memory interrupt. //?? fwprintf(stdout, L"TEST detected signal memory irq: %i\n", *((int*) *irq)); } // CAUTION! The boolean logic expression is necessary, because: // - first case: irq is null which means that NO OTHER irq has been checked before // - second case: irq is not null which means some other irq has been retrieved from // internal memory and checked before, BUT its value is zero anyway (irq not set) // // In both cases, this interrupt is retrieved and checked. // Otherwise, if an irq was retrieved AND its value is not zero (irq is set), // this and further interrupts are NOT checked. if ((*irq == *NULL_POINTER_MEMORY_MODEL) || ((*irq != *NULL_POINTER_MEMORY_MODEL) && (*((int*) *irq) == *NUMBER_0_INTEGER_MEMORY_MODEL))) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Detected gnu/linux console interrupt."); // Get gnu/linux console interrupt request. copy_array_forward(p0, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) GNU_LINUX_CONSOLE_INTERRUPT_REQUEST_INTERNAL_MEMORY_MEMORY_NAME); // Get gnu/linux console mutex. copy_array_forward(p1, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) GNU_LINUX_CONSOLE_MUTEX_INTERNAL_MEMORY_MEMORY_NAME); // Get gnu/linux console handler. copy_array_forward(p2, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) GNU_LINUX_CONSOLE_HANDLER_INTERNAL_MEMORY_MEMORY_NAME); //?? fwprintf(stdout, L"TEST detected gnu/linux console irq: %i\n", *((int*) *irq)); } // CAUTION! The boolean logic expression is necessary, because: // - first case: irq is null which means that NO OTHER irq has been checked before // - second case: irq is not null which means some other irq has been retrieved from // internal memory and checked before, BUT its value is zero anyway (irq not set) // // In both cases, this interrupt is retrieved and checked. // Otherwise, if an irq was retrieved AND its value is not zero (irq is set), // this and further interrupts are NOT checked. if ((*irq == *NULL_POINTER_MEMORY_MODEL) || ((*irq != *NULL_POINTER_MEMORY_MODEL) && (*((int*) *irq) == *NUMBER_0_INTEGER_MEMORY_MODEL))) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Detected x window system interrupt."); // Get x window system interrupt request. copy_array_forward(p0, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) X_WINDOW_SYSTEM_INTERRUPT_REQUEST_INTERNAL_MEMORY_MEMORY_NAME); // Get x window system mutex. copy_array_forward(p1, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) X_WINDOW_SYSTEM_MUTEX_INTERNAL_MEMORY_MEMORY_NAME); // Get x window system handler. copy_array_forward(p2, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) X_WINDOW_SYSTEM_HANDLER_INTERNAL_MEMORY_MEMORY_NAME); //?? fwprintf(stdout, L"TEST detected x window system irq: %i\n", *((int*) *irq)); } // CAUTION! The boolean logic expression is necessary, because: // - first case: irq is null which means that NO OTHER irq has been checked before // - second case: irq is not null which means some other irq has been retrieved from // internal memory and checked before, BUT its value is zero anyway (irq not set) // // In both cases, this interrupt is retrieved and checked. // Otherwise, if an irq was retrieved AND its value is not zero (irq is set), // this and further interrupts are NOT checked. if ((*irq == *NULL_POINTER_MEMORY_MODEL) || ((*irq != *NULL_POINTER_MEMORY_MODEL) && (*((int*) *irq) == *NUMBER_0_INTEGER_MEMORY_MODEL))) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Detected www service interrupt."); // Get www service interrupt request. copy_integer((void*) &i, (void*) WWW_BASE_INTERNAL_MEMORY_MEMORY_NAME); calculate_integer_add((void*) &i, (void*) SOCKET_INTERRUPT_REQUEST_INTERNAL_MEMORY_MEMORY_NAME); copy_array_forward(p0, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) &i); // Get www service mutex. copy_integer((void*) &i, (void*) WWW_BASE_INTERNAL_MEMORY_MEMORY_NAME); calculate_integer_add((void*) &i, (void*) SOCKET_MUTEX_INTERNAL_MEMORY_MEMORY_NAME); copy_array_forward(p1, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) &i); // Get www service handler. copy_integer((void*) &i, (void*) WWW_BASE_INTERNAL_MEMORY_MEMORY_NAME); calculate_integer_add((void*) &i, (void*) SOCKET_HANDLER_INTERNAL_MEMORY_MEMORY_NAME); copy_array_forward(p2, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) &i); //?? fwprintf(stdout, L"TEST detected www service irq: %i\n", *((int*) *irq)); } // CAUTION! The boolean logic expression is necessary, because: // - first case: irq is null which means that NO OTHER irq has been checked before // - second case: irq is not null which means some other irq has been retrieved from // internal memory and checked before, BUT its value is zero anyway (irq not set) // // In both cases, this interrupt is retrieved and checked. // Otherwise, if an irq was retrieved AND its value is not zero (irq is set), // this and further interrupts are NOT checked. if ((*irq == *NULL_POINTER_MEMORY_MODEL) || ((*irq != *NULL_POINTER_MEMORY_MODEL) && (*((int*) *irq) == *NUMBER_0_INTEGER_MEMORY_MODEL))) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Detected cyboi service interrupt."); // Get cyboi service interrupt request. copy_integer((void*) &i, (void*) CYBOI_BASE_INTERNAL_MEMORY_MEMORY_NAME); calculate_integer_add((void*) &i, (void*) SOCKET_INTERRUPT_REQUEST_INTERNAL_MEMORY_MEMORY_NAME); copy_array_forward(p0, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) &i); // Get cyboi service mutex. copy_integer((void*) &i, (void*) CYBOI_BASE_INTERNAL_MEMORY_MEMORY_NAME); calculate_integer_add((void*) &i, (void*) SOCKET_MUTEX_INTERNAL_MEMORY_MEMORY_NAME); copy_array_forward(p1, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) &i); // Get cyboi service handler. copy_integer((void*) &i, (void*) CYBOI_BASE_INTERNAL_MEMORY_MEMORY_NAME); calculate_integer_add((void*) &i, (void*) SOCKET_HANDLER_INTERNAL_MEMORY_MEMORY_NAME); copy_array_forward(p2, p3, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) VALUE_PRIMITIVE_MEMORY_NAME, (void*) &i); fwprintf(stdout, L"TEST detected cyboi service irq: %i\n", *((int*) *irq)); } // CAUTION! The boolean logic AND expression && is necessary, because: // - first case: irq is null which means that NO OTHER irq has been checked before // - second case: irq is not null which means some other irq has been retrieved from // internal memory and checked before, BUT its value is zero anyway (irq not set) // // In both cases, this interrupt is retrieved and checked. // Otherwise, if an irq was retrieved AND its value is not zero (irq is set), // this and further interrupts are NOT checked. if ((*irq == *NULL_POINTER_MEMORY_MODEL) || ((*irq != *NULL_POINTER_MEMORY_MODEL) && (*((int*) *irq) == *NUMBER_0_INTEGER_MEMORY_MODEL))) { log_terminated_message((void*) WARNING_LEVEL_LOG_MODEL, (void*) L"Could not check for interrupt requests. No interrupt request is set."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not check for interrupt requests. The interrupt request argument is null."); } }
/** * Starts up the socket. * * @param p0 the internal memory array * @param p1 the namespace model * @param p2 the namespace model count * @param p3 the style model * @param p4 the style model count * @param p5 the socket file name or host address model (depending on the socket type: local, ipv4, ipv6) * @param p6 the socket file name or host address model count * @param p7 the port model * @param p8 the base internal */ void startup_socket(void* p0, void* p1, void* p2, void* p3, void* p4, void* p5, void* p6, void* p7, void* p8) { if (p8 != *NULL_POINTER_MEMORY_MODEL) { int* base = (int*) p8; log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Startup socket."); // The socket namespace. int sn = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // The address namespace. int an = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // The communication style. int st = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // The ipv4 host address of this system. struct in_addr ha4; // The ipv6 host address of this system. struct in6_addr ha6; // // CAUTION! Do use pointers for the addresses declared below, // and not only the structure as type, so that the different // socket addresses can be processed uniformly below! // // The local socket address of this system. struct sockaddr_un* la = (struct sockaddr_un*) *NULL_POINTER_MEMORY_MODEL; // The ipv4 internet socket address of this system. struct sockaddr_in* ia4 = (struct sockaddr_in*) *NULL_POINTER_MEMORY_MODEL; // The ipv6 internet socket address of this system. struct sockaddr_in6* ia6 = (struct sockaddr_in6*) *NULL_POINTER_MEMORY_MODEL; // The communication partner local socket address. struct sockaddr_un* pla = (struct sockaddr_un*) *NULL_POINTER_MEMORY_MODEL; // The communication partner ipv4 internet socket address. struct sockaddr_in* pia4 = (struct sockaddr_in*) *NULL_POINTER_MEMORY_MODEL; // The communication partner ipv6 internet socket address. struct sockaddr_in6* pia6 = (struct sockaddr_in6*) *NULL_POINTER_MEMORY_MODEL; // The socket address size of this system. int* as = (int*) *NULL_POINTER_MEMORY_MODEL; // The communication partner socket address size. int* pas = (int*) *NULL_POINTER_MEMORY_MODEL; // The socket of this system. int* s = (int*) *NULL_POINTER_MEMORY_MODEL; // The communication partner socket. int* ps = (int*) *NULL_POINTER_MEMORY_MODEL; // The character buffer being used in the thread procedure receiving messages via socket. void* b = *NULL_POINTER_MEMORY_MODEL; int* bc = (int*) *NULL_POINTER_MEMORY_MODEL; int* bs = (int*) *NULL_POINTER_MEMORY_MODEL; // The internal memory index. int i = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // The result. int r = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // Get socket- and address namespace. startup_socket_get_namespace((void*) &sn, (void*) &an, p1, p2); // Get socket communication style. startup_socket_get_style((void*) &st, p3, p4); // Get host address constant. if (an == AF_INET) { startup_socket_get_host_address((void*) &ha4, p5, p6, (void*) &an); } else if (an == AF_INET6) { startup_socket_get_host_address((void*) &ha6, p5, p6, (void*) &an); } // Allocate socket address size of this system. allocate((void*) &as, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION); // Allocate communication partner socket address size. allocate((void*) &pas, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION); // Allocate socket of this system. allocate((void*) &s, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION); // Allocate communication partner socket. allocate((void*) &ps, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION); // Initialise socket address size of this system. copy_integer(as, (void*) NUMBER_0_INTEGER_MEMORY_MODEL); // Initialise communication partner socket address size. copy_integer(pas, (void*) NUMBER_0_INTEGER_MEMORY_MODEL); if (an == AF_LOCAL) { // CAUTION! The following line CANNOT be used: // *as = sizeof(struct sockaddr_un); // because the compiler brings the error // "invalid application of 'sizeof' to incomplete type 'struct sockaddr_un'". // The reason is the "sun_path" field of the "sockaddr_un" structure, // which is a character array whose size is unknown at compilation time. // // The size of the "sun_path" character array is therefore set // to the fixed size of 108. // The number "108" is the limit as set by the gnu c library! // Its documentation called it a "magic number" and does not // know why this limit exists. // // With the known type "short int" of the "sun_family" field and // a fixed size "108" of the "sun_path" field, the overall size of // the "sockaddr_un" structure can be calculated as sum. calculate_integer_add(as, (void*) SIGNED_SHORT_INTEGER_INTEGRAL_TYPE_SIZE); calculate_integer_add(as, (void*) NUMBER_108_INTEGER_MEMORY_MODEL); calculate_integer_add(pas, (void*) SIGNED_SHORT_INTEGER_INTEGRAL_TYPE_SIZE); calculate_integer_add(pas, (void*) NUMBER_108_INTEGER_MEMORY_MODEL); } else if (an == AF_INET) { calculate_integer_add(as, (void*) INTERNET_PROTOCOL_4_SOCKET_ADDRESS_SOCKET_TYPE_SIZE); calculate_integer_add(pas, (void*) INTERNET_PROTOCOL_4_SOCKET_ADDRESS_SOCKET_TYPE_SIZE); } else if (an == AF_INET6) { calculate_integer_add(as, (void*) INTERNET_PROTOCOL_6_SOCKET_ADDRESS_SOCKET_TYPE_SIZE); calculate_integer_add(pas, (void*) INTERNET_PROTOCOL_6_SOCKET_ADDRESS_SOCKET_TYPE_SIZE); } // Allocate socket address of this system. // Allocate communication partner socket address. if (an == AF_LOCAL) { la = (struct sockaddr_un*) malloc(*as); pla = (struct sockaddr_un*) malloc(*pas); } else if (an == AF_INET) { ia4 = (struct sockaddr_in*) malloc(*as); pia4 = (struct sockaddr_in*) malloc(*pas); } else if (an == AF_INET6) { ia6 = (struct sockaddr_in6*) malloc(*as); pia6 = (struct sockaddr_in6*) malloc(*pas); } // Initialise socket address of this system. // CAUTION! Do NOT initialise communication partner socket address! // It gets initialised only before sending, or at reception of a message. if (an == AF_LOCAL) { startup_socket_initialise_local_socket_address((void*) &la, p5, p6); } else if (an == AF_INET) { startup_socket_initialise_ipv4_socket_address((void*) &ia4, (void*) &ha4, p7); } else if (an == AF_INET6) { startup_socket_initialise_ipv6_socket_address((void*) &ia6, (void*) &ha6, p7); } // Allocate character buffer count and size. allocate((void*) &bc, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION); allocate((void*) &bs, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) INTEGER_MEMORY_ABSTRACTION); // Initialise character buffer count, size. // A possible initial size is 2048, which should // suffice for transferring standard data over tcp/ip. // Another possible size could be 8192. copy_integer(bc, (void*) NUMBER_0_INTEGER_MEMORY_MODEL); copy_integer(bs, (void*) NUMBER_0_INTEGER_MEMORY_MODEL); // Allocate character buffer. // // CAUTION! Allocate character buffer only AFTER // the buffer size has been initialised above! allocate((void*) &b, (void*) bs, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION); // Set socket address of this system. // Set communication partner socket address. if (an == AF_LOCAL) { i = *base + *SOCKET_ADDRESS_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &la, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); i = *base + *SOCKET_COMMUNICATION_PARTNER_ADDRESS_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &pla, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); } else if (an == AF_INET) { i = *base + *SOCKET_ADDRESS_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &ia4, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); i = *base + *SOCKET_COMMUNICATION_PARTNER_ADDRESS_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &pia4, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); } else if (an == AF_INET6) { i = *base + *SOCKET_ADDRESS_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &ia6, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); i = *base + *SOCKET_COMMUNICATION_PARTNER_ADDRESS_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &pia6, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); } // Set socket address size of this system. i = *base + *SOCKET_ADDRESS_SIZE_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &as, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); // Set communication partner socket address size. i = *base + *SOCKET_COMMUNICATION_PARTNER_ADDRESS_SIZE_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &pas, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); // Set socket of this system. i = *base + *SOCKET_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &s, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); // Set communication partner socket. i = *base + *SOCKET_COMMUNICATION_PARTNER_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &ps, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); // Set character buffer. i = *base + *SOCKET_CHARACTER_BUFFER_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &b, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); i = *base + *SOCKET_CHARACTER_BUFFER_COUNT_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &bc, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); i = *base + *SOCKET_CHARACTER_BUFFER_SIZE_INTERNAL_MEMORY_MEMORY_NAME; copy_array_forward(p0, (void*) &bs, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) &i, (void*) VALUE_PRIMITIVE_MEMORY_NAME); // Initialise error number. // It is a global variable/ function and other operations // may have set some value that is not wanted here. // // CAUTION! Initialise the error number BEFORE calling the procedure // that might cause an error. errno = *NUMBER_0_INTEGER_MEMORY_MODEL; // Initialise server socket. // // param 0: namespace // param 1: style // param 2: protocol // // CAUTION! Use prefix "PF_" here and NOT "AF_"! // The latter is to be used for address family assignment. // See further below! *s = socket(sn, st, *NUMBER_0_INTEGER_MEMORY_MODEL); if (*s >= *NUMBER_0_INTEGER_MEMORY_MODEL) { // Set non-blocking mode for the socket file descriptor. // // If the O_NONBLOCK flag (a bit) is set, read requests on the socket // (file) can return immediately with a failure status if there is no // input immediately available, instead of blocking. Likewise, write // requests can also return immediately with a failure status if the // output can't be written immediately. // // CAUTION! The "select" procedure was NOT used to make this socket // non-blocking, because it has some overhead in that other sockets // need to be considered and their file descriptors handed over as // parameter. // A simple "sleep" procedure is considered to be a more simple and // clean solution here. /*?? // Get file status flags. int fl = fcntl(*s, F_GETFL, NUMBER_0_INTEGER); if (fl != *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL) { // Set non-blocking flag (bit). fl |= O_NONBLOCK; // Store modified flag word in the file descriptor. fcntl(*s, F_SETFL, fl); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket / set non-blocking mode. The socket file descriptor flags could not be read."); } */ // Initialise error number. // It is a global variable/ function and other operations // may have set some value that is not wanted here. // // CAUTION! Initialise the error number BEFORE calling the procedure // that might cause an error. errno = *NUMBER_0_INTEGER_MEMORY_MODEL; // Bind socket number to socket address. if (an == AF_LOCAL) { r = bind(*s, (struct sockaddr*) la, *((socklen_t*) as)); } else if (an == AF_INET) { r = bind(*s, (struct sockaddr*) ia4, *((socklen_t*) as)); fwprintf(stdout, L"TEST: startup socket bind s: %i \n", *s); sleep(2); } else if (an == AF_INET6) { r = bind(*s, (struct sockaddr*) ia6, *((socklen_t*) as)); } if (r >= *NUMBER_0_INTEGER_MEMORY_MODEL) { if (st == SOCK_STREAM) { // Reset result. r = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // Initialise error number. // It is a global variable/ function and other operations // may have set some value that is not wanted here. // // CAUTION! Initialise the error number BEFORE calling the procedure // that might cause an error. errno = *NUMBER_0_INTEGER_MEMORY_MODEL; // CAUTION! Datagram sockets do NOT have connections, // which is why the "listen" procedure is only called // for stream sockets here. // Enable socket to accept connections, thus making it a server socket. // The second parameter determines the number of possible // pending client connection requests. r = listen(*s, *NUMBER_1_INTEGER_MEMORY_MODEL); fwprintf(stdout, L"TEST: startup socket listen s: %i \n", *s); sleep(2); if (r < *NUMBER_0_INTEGER_MEMORY_MODEL) { if (errno == EBADF) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The argument socket is not a valid file descriptor."); } else if (errno == ENOTSOCK) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The argument socket is not a socket."); } else if (errno == EOPNOTSUPP) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The socket does not support this operation."); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. An unknown error occured while listening at the socket."); } } } } else { if (errno == EBADF) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The socket argument is not a valid file descriptor."); } else if (errno == ENOTSOCK) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The descriptor socket is not a socket."); } else if (errno == EADDRNOTAVAIL) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The specified address is not available on this machine."); } else if (errno == EADDRINUSE) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The specified address is already used by some other socket."); } else if (errno == EINVAL) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The socket socket already has an address."); } else if (errno == EACCES) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The permission to access the requested address is missing. (In the internet domain, only the super-user is allowed to specify a port number in the range 0 through IPPORT_RESERVED minus one; see the section called 'Internet Ports'."); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. An unknown error occured while binding the socket to the address."); } } } else { if (errno == EPROTONOSUPPORT) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The protocol or style is not supported by the namespace specified."); } else if (errno == EMFILE) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The process already has too many file descriptors open."); } else if (errno == ENFILE) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The system already has too many file descriptors open."); } else if (errno == EACCES) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The process does not have the privilege to create a socket of the specified style or protocol."); } else if (errno == ENOBUFS) { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The system ran out of internal buffer space."); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. An unknown error occured while initialising the socket."); } } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not start up socket. The base internal is null."); } }
int pow_mod(unsigned char** result,unsigned char* p,unsigned char* q, unsigned char* r,unsigned int keyLengthBytes){ std::set_new_handler(newh); Array<integer> factors; integer div=hex_to_integer(q,keyLengthBytes,0); int siz=keyLengthBytes; integer power_of_two=create_integer(siz); set_zero_integer(power_of_two); integer zero=create_integer(1); set_zero_integer(zero); integer two=string_to_integer("2"); integer one=string_to_integer("1"); int i=0; integer div_temp=create_integer(div.num_components); integer rem=create_integer(div.num_components+2); while(compare_integers(div, zero) == 1){ set_zero_integer(rem); mod_integer(div, two,rem); copy_integer(div,div_temp); divide_small_integer(div_temp,2,div); if(compare_integers(rem, zero) == 1){ integer ptt=create_integer(power_of_two.num_components); copy_integer(power_of_two,ptt); factors.pushBack(ptt); } add_integer(power_of_two,one,power_of_two); i++; } free_integer(rem); free_integer(div_temp); Array<integer> partial_results; integer part_res=hex_to_integer(p,keyLengthBytes,2); integer ri=hex_to_integer(r,keyLengthBytes,1); integer idx = create_integer(part_res.num_components); set_zero_integer(idx); integer part_res_temp1=create_integer(part_res.num_components); integer part_res_temp2=create_integer(part_res.num_components); integer part_res_temp3=create_integer(part_res.num_components); for(int i=0; i<factors.size(); i++){ while(compare_integers(factors[i],idx)==1){ copy_integer(part_res,part_res_temp1); copy_integer(part_res,part_res_temp2); multiply_integer(part_res_temp1,part_res_temp2,part_res); copy_integer(part_res,part_res_temp3); mod_integer(part_res_temp3,ri,part_res); add_integer(idx,one,idx); } integer ptt=create_integer(part_res.num_components); copy_integer(part_res,ptt); partial_results.pushBack(ptt); } free_integer(part_res_temp1); free_integer(part_res_temp2); free_integer(part_res_temp3); integer resulti=create_integer(ri.num_components+1); set_zero_integer(resulti); resulti.c[0]=1; integer resulti_temp=create_integer(resulti.num_components); integer resulti_temp2=create_integer(resulti.num_components); for(int i=0; i<partial_results.size(); i++){ copy_integer(resulti,resulti_temp); multiply_integer(resulti_temp,partial_results[i],resulti); copy_integer(resulti,resulti_temp2); mod_integer(resulti_temp2,ri,resulti); } free_integer(resulti_temp); free_integer(resulti_temp2); int lol=integer_to_binary(result,resulti,keyLengthBytes); return lol; }