Exemplo n.º 1
0
ENTRYPOINT void init_commander(ModeInfo *mi) 
{
  commander_conf *cp;
	int i;
	int do_which = -1;

  if(!commander) {
    commander = (commander_conf *)calloc(MI_NUM_SCREENS(mi), sizeof(commander_conf));
    if(!commander) return;
  }
  cp = &commander[MI_SCREEN(mi)];

  if ((cp->glx_context = init_GL(mi)) != NULL) {
    init_gl(mi);
    cp->which = -1;
    reshape_commander(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  } else {
    MI_CLEARWINDOW(mi);
  }

  {
    double spin_speed = 0.7 * speed;
    double spin_accel = 0.1 * speed;

    cp->rot = make_rotator (spin_speed, spin_speed, spin_speed,
                            spin_accel, 0, True);
    cp->trackball = gltrackball_init (True);
  }

	/* figure out which ship to display */

	/* do_which=-1 for "random" mode */
	if(!strcasecmp (do_which_str, "random"))
		;
	else {
		for(i=0;i<NUM_ELEM(ship_names);i++) {
			if(!strcasecmp(do_which_str, ship_names[i])) {
					do_which=i;
					cp->which=i;
			}
		}
		if(do_which<0) {
			fprintf(stderr, "%s: no such ship: \"%s\"\n",
					progname, do_which_str);
			exit(1);
		}
	}

	/* FIXME (what?) */
	if(do_which==-1) {
		cp->which=random() % NUM_ELEM(ship_names);
	}

	new_ship(mi);

}
Exemplo n.º 2
0
int main(void) {
    FILE *file = fopen(IMAGE_NAME ".xbm", "w");
    fputs("#define " IMAGE_NAME "_width 8\n", file);
    fprintf(file, "#define " IMAGE_NAME "_height %d\n", NUM_ELEM(large_image));
    fputs("static unsigned char " IMAGE_NAME "_bits[] = {\n", file);
    for (int i=0; i<NUM_ELEM(large_image); i++) {
        fprintf(file, "%s0x%x", (i==0?"   ":", "), large_image[i]);
    }
    fputs(" };\n", file);
    fclose(file);
    exit(EXIT_SUCCESS);
}
Exemplo n.º 3
0
int main()
{

    int i;
    
    quicksort(nums, NUM_ELEM(nums));
    
    #ifdef IO
    for (i = 0; i < NUM_ELEM(nums); ++i) {
        writeint(nums[i]);
    }
    #endif
    
    asm("swi 0x11");
}
Exemplo n.º 4
0
/* Initialize the mcore_elf_howto_table, so that linear accesses can be done.  */
static void
mcore_elf_howto_init ()
{
  unsigned int i;

  for (i = NUM_ELEM (mcore_elf_howto_raw); i--;)
    {
      unsigned int type;

      type = mcore_elf_howto_raw[i].type;

      BFD_ASSERT (type < NUM_ELEM (mcore_elf_howto_table));

      mcore_elf_howto_table [type] = & mcore_elf_howto_raw [i];
    }
}
Exemplo n.º 5
0
SkShader*
skiaCreateRadialGradientShader(const shapes_t *shape)
{
    double radius = shape->radius;
    SkPoint center;
    SkColor colors[2];

    colors[0] = skiaRandomColor();
    colors[1] = skiaRandomColor();
    if (shape->radius > 0) {
        center.set(shape->x + shape->radius, shape->y + shape->radius);
    } else if (shape->width > shape->height) {
        radius = shape->height/2;
        center.set(
            shape->x + radius + ((double)rnd()*shape->width)/RAND_MAX,
            shape->y + radius
            );
    } else {
        radius = shape->width/2;
        center.set(
            shape->x + radius,
            shape->y + radius + ((double)rnd()*shape->height)/RAND_MAX
            );
    }

    return SkGradientShader::CreateRadial(
        center, radius,
        colors, NULL, NUM_ELEM(colors),
        SkShader::kClamp_TileMode);
}
Exemplo n.º 6
0
static reloc_howto_type *
elf32_arm_howto_from_type (unsigned int r_type)
{
    if (r_type < NUM_ELEM (elf32_arm_howto_table))
        return &elf32_arm_howto_table[r_type];

    switch (r_type)
    {
    case R_ARM_GOT_PREL:
        return &elf32_arm_got_prel;

    case R_ARM_GNU_VTINHERIT:
        return &elf32_arm_vtinherit_howto;

    case R_ARM_GNU_VTENTRY:
        return &elf32_arm_vtentry_howto;

    case R_ARM_THM_PC11:
        return &elf32_arm_thm_pc11_howto;

    case R_ARM_THM_PC9:
        return &elf32_arm_thm_pc9_howto;

    default:
        return NULL;
    }
}
Exemplo n.º 7
0
void fortune_cookie(char msg[])
{
  printf("Message reads: %s\n",msg);
  printf("msg occupies %lu bytes\n", NUM_ELEM(msg));
  printf("The quote string is stored at: %p\n",msg);

}
Exemplo n.º 8
0
static int get_key_alg(const char *key_alg_str)
{
	int i;

	for (i = 0 ; i < NUM_ELEM(key_algs_str) ; i++) {
		if (0 == strcmp(key_alg_str, key_algs_str[i])) {
			return i;
		}
	}

	return -1;
}
Exemplo n.º 9
0
void convolve3d_m_cl(const MCLMatrix3D::Ptr& video,
                      const MCLMatrix3D::Ptr& kernel,
                      MCLMatrix3D::Ptr& output,
                      unsigned int algorithm)
{
    assert(algorithm < NUM_ELEM(convolution_algorithm_cl));
    if (convolution_algorithm_cl[algorithm](video, kernel, output)) {
		debug_algorithm_used_cl = algorithm;
		return;
	}
	
    throw_runtime_error("Unable to find convolution algorithm");
}
Exemplo n.º 10
0
SkShader*
skiaCreateLinearGradientShader(int y1, int y2)
{
    SkColor linearColors[2];
    SkPoint linearPoints[2];

    linearColors[0] = skiaRandomColor();
    linearColors[1] = skiaRandomColor();
    linearPoints[0].fX = SkIntToScalar(0);
    linearPoints[0].fY = SkIntToScalar(y1);
    linearPoints[1].fX = SkIntToScalar(0);
    linearPoints[1].fY = SkIntToScalar(y2);

    return SkGradientShader::CreateLinear(
        linearPoints, linearColors, NULL, NUM_ELEM(linearColors),
        SkShader::kClamp_TileMode);
}
Exemplo n.º 11
0
#include <util/delay.h>
#include "bitops.h"

void delay_ms( uint16_t milliseconds)
{
   for( ; milliseconds > 0; milliseconds--)
   {
      _delay_ms( 1);
   }
} 
const static int image[] = {
   0x18, 0x3c, 0x66, 0x42, 0xc3, 0x81, 0xff, 0x81, 0xff, 0x81, 0xc3, 0x42,
   0x66, 0x3c, 0x18,
};

int imagesize = NUM_ELEM(image);


// this function is called when timer1 compare matches OCR1A
uint8_t j = 0;
SIGNAL( TIMER1_COMPA_vect ) {
  if (j >= imagesize) 
    j = 0;

  PORTB = image[j];
 
  j++;
}

int main(void) {
Exemplo n.º 12
0
CK_RV
jpake_Final(HASH_HashType hashType, const CK_NSS_JPAKEFinalParams * param,
            SFTKObject * sourceKey, SFTKObject * key)
{
    PLArenaPool * arena;
    SECItem K;
    PQGParams pqg;
    CK_RV crv;
    SECItem peerID, signerID, x2s, x2, gx1, gx2, gx3, gx4;
    SFTKItemTemplate sourceAttrs[] = {
        { CKA_NSS_JPAKE_PEERID, &peerID },
        { CKA_NSS_JPAKE_SIGNERID, &signerID },
        { CKA_PRIME, &pqg.prime },
        { CKA_SUBPRIME, &pqg.subPrime },
        { CKA_NSS_JPAKE_X2,  &x2  },
        { CKA_NSS_JPAKE_X2S, &x2s },
        { CKA_NSS_JPAKE_GX1, &gx1 },
        { CKA_NSS_JPAKE_GX2, &gx2 },
        { CKA_NSS_JPAKE_GX3, &gx3 },
        { CKA_NSS_JPAKE_GX4, &gx4 }
    };

    PORT_Assert(param != NULL);
    PORT_Assert(sourceKey != NULL);
    PORT_Assert(key != NULL);

    arena = PORT_NewArena(NSS_SOFTOKEN_DEFAULT_CHUNKSIZE);
    if (arena == NULL)
        crv = CKR_HOST_MEMORY;
    
    /* TODO: verify key type CKK_NSS_JPAKE_ROUND2 */

    crv = sftk_MultipleAttribute2SecItem(arena, sourceKey, sourceAttrs,
                                         NUM_ELEM(sourceAttrs));

    /* Calculate base for B=base^x4s */
    if (crv == CKR_OK) {
        pqg.base.data = NULL;
        crv = jpake_mapStatus(JPAKE_Round2(arena, &pqg.prime, &pqg.subPrime,
                                           &gx1, &gx2, &gx3, &pqg.base,
                                           NULL, NULL, NULL),
                              CKR_MECHANISM_PARAM_INVALID);
    }

    /* Verify zero-knowledge proof for B */
    if (crv == CKR_OK)
        crv = jpake_Verify(arena, &pqg, hashType, &signerID,
                           peerID.data, peerID.len, &param->B);
    if (crv == CKR_OK) {
        SECItem B;
        B.data = param->B.pGX;
        B.len = param->B.ulGXLen;
        K.data = NULL;
        crv = jpake_mapStatus(JPAKE_Final(arena, &pqg.prime, &pqg.subPrime,
                                          &x2, &gx4, &x2s, &B, &K),
                              CKR_MECHANISM_PARAM_INVALID);
    }

    /* Save key material into CKA_VALUE. */
    if (crv == CKR_OK)
        crv = sftk_forceAttribute(key, CKA_VALUE, K.data, K.len);

    if (crv == CKR_OK)
        crv = jpake_enforceKeyType(key, CKK_GENERIC_SECRET);

    PORT_FreeArena(arena, PR_TRUE);
    return crv;
}
Exemplo n.º 13
0
CK_RV
jpake_Round2(HASH_HashType hashType, CK_NSS_JPAKERound2Params * params,
             SFTKObject * sourceKey, SFTKObject * key)
{
    CK_RV crv;
    PLArenaPool * arena;
    PQGParams pqg;
    SECItem signerID, x2, gx1, gx2;
    SFTKItemTemplate sourceAttrs[] = { 
        { CKA_PRIME, &pqg.prime },
        { CKA_SUBPRIME, &pqg.subPrime },
        { CKA_BASE, &pqg.base },
        { CKA_NSS_JPAKE_SIGNERID, &signerID },
        { CKA_NSS_JPAKE_X2,  &x2 },
        { CKA_NSS_JPAKE_GX1, &gx1 },
        { CKA_NSS_JPAKE_GX2, &gx2 },
    };
    SECItem x2s, gx3, gx4;
    const SFTKItemTemplate copiedAndGeneratedAttrs[] = {
        { CKA_NSS_JPAKE_SIGNERID, &signerID },
        { CKA_PRIME, &pqg.prime },
        { CKA_SUBPRIME, &pqg.subPrime },
        { CKA_NSS_JPAKE_X2,  &x2  },
        { CKA_NSS_JPAKE_X2S, &x2s },
        { CKA_NSS_JPAKE_GX1, &gx1 },
        { CKA_NSS_JPAKE_GX2, &gx2 },
        { CKA_NSS_JPAKE_GX3, &gx3 },
        { CKA_NSS_JPAKE_GX4, &gx4 }
    };
    SECItem peerID;

    PORT_Assert(params != NULL);
    PORT_Assert(sourceKey != NULL);
    PORT_Assert(key != NULL);

    arena = PORT_NewArena(NSS_SOFTOKEN_DEFAULT_CHUNKSIZE);
    if (arena == NULL)
        crv = CKR_HOST_MEMORY;

    /* TODO: check CKK_NSS_JPAKE_ROUND1 */

    crv = sftk_MultipleAttribute2SecItem(arena, sourceKey, sourceAttrs,
                                         NUM_ELEM(sourceAttrs));

    /* Get the peer's ID out of the template and sanity-check it. */
    if (crv == CKR_OK)
        crv = sftk_Attribute2SecItem(arena, &peerID, key,
                                     CKA_NSS_JPAKE_PEERID);
    if (crv == CKR_OK && (peerID.data == NULL || peerID.len == 0))
        crv = CKR_TEMPLATE_INCOMPLETE;
    if (crv == CKR_OK && SECITEM_CompareItem(&signerID, &peerID) == SECEqual)
        crv = CKR_TEMPLATE_INCONSISTENT;

    /* Verify zero-knowledge proofs for g^x3 and g^x4 */
    if (crv == CKR_OK)
        crv = jpake_Verify(arena, &pqg, hashType, &signerID,
                           peerID.data, peerID.len, &params->gx3);
    if (crv == CKR_OK)
        crv = jpake_Verify(arena, &pqg, hashType, &signerID,
                           peerID.data, peerID.len, &params->gx4);

    /* Calculate the base and x2s for A=base^x2s */
    if (crv == CKR_OK) {
        SECItem s;
        s.data = params->pSharedKey;
        s.len = params->ulSharedKeyLen;
        gx3.data = params->gx3.pGX;
        gx3.len = params->gx3.ulGXLen;
        gx4.data = params->gx4.pGX;
        gx4.len = params->gx4.ulGXLen;
        pqg.base.data = NULL;
        x2s.data = NULL;
        crv = jpake_mapStatus(JPAKE_Round2(arena, &pqg.prime, &pqg.subPrime,
                                           &gx1, &gx3, &gx4, &pqg.base, 
                                           &x2, &s, &x2s),
                              CKR_MECHANISM_PARAM_INVALID);
    }

    /* Generate A=base^x2s and its zero-knowledge proof. */
    if (crv == CKR_OK)
        crv = jpake_Sign(arena, &pqg, hashType, &signerID, &x2s, &params->A);

    /* Copy P and Q from the ROUND1 key to the ROUND2 key and save the values
       needed for the final key material derivation into CKA_VALUE. */
    if (crv == CKR_OK)
        crv = sftk_forceAttribute(key, CKA_PRIME, pqg.prime.data,
                                  pqg.prime.len);
    if (crv == CKR_OK)
        crv = sftk_forceAttribute(key, CKA_SUBPRIME, pqg.subPrime.data,
                                  pqg.subPrime.len);
    if (crv == CKR_OK) {
        crv = jpake_MultipleSecItem2Attribute(key, copiedAndGeneratedAttrs,
                                              NUM_ELEM(copiedAndGeneratedAttrs));
    }

    if (crv == CKR_OK)
        crv = jpake_enforceKeyType(key, CKK_NSS_JPAKE_ROUND2);

    PORT_FreeArena(arena, PR_TRUE);
    return crv;
}
Exemplo n.º 14
0
CK_RV
jpake_Round1(HASH_HashType hashType, CK_NSS_JPAKERound1Params * params,
             SFTKObject * key)
{
    CK_RV crv;
    PQGParams pqg;
    PLArenaPool * arena;
    SECItem signerID;
    SFTKItemTemplate templateAttrs[] = {
        { CKA_PRIME, &pqg.prime },
        { CKA_SUBPRIME, &pqg.subPrime },
        { CKA_BASE, &pqg.base },
        { CKA_NSS_JPAKE_SIGNERID, &signerID }
    };
    SECItem x2, gx1, gx2;
    const SFTKItemTemplate generatedAttrs[] = {
        { CKA_NSS_JPAKE_X2,  &x2  },
        { CKA_NSS_JPAKE_GX1, &gx1 },
        { CKA_NSS_JPAKE_GX2, &gx2 },
    };
    SECItem x1;

    PORT_Assert(params != NULL);
    PORT_Assert(key != NULL);

    arena = PORT_NewArena(NSS_SOFTOKEN_DEFAULT_CHUNKSIZE);
    if (arena == NULL)
        crv = CKR_HOST_MEMORY;

    crv = sftk_MultipleAttribute2SecItem(arena, key, templateAttrs,
                                         NUM_ELEM(templateAttrs));

    if (crv == CKR_OK && (signerID.data == NULL || signerID.len == 0))
        crv = CKR_TEMPLATE_INCOMPLETE;

    /* generate x1, g^x1 and the proof of knowledge of x1 */
    if (crv == CKR_OK) {
        x1.data = NULL;
        crv = jpake_mapStatus(DSA_NewRandom(arena, &pqg.subPrime, &x1),
                              CKR_TEMPLATE_INCONSISTENT);
    }
    if (crv == CKR_OK)
        crv = jpake_Sign(arena, &pqg, hashType, &signerID, &x1, &params->gx1);

    /* generate x2, g^x2 and the proof of knowledge of x2 */
    if (crv == CKR_OK) {
        x2.data = NULL;
        crv = jpake_mapStatus(DSA_NewRandom(arena, &pqg.subPrime, &x2),
                              CKR_TEMPLATE_INCONSISTENT);
    }
    if (crv == CKR_OK)
        crv = jpake_Sign(arena, &pqg, hashType, &signerID, &x2, &params->gx2);

    /* Save the values needed for round 2 into CKA_VALUE */
    if (crv == CKR_OK) {
        gx1.data = params->gx1.pGX;
        gx1.len = params->gx1.ulGXLen;
        gx2.data = params->gx2.pGX;
        gx2.len = params->gx2.ulGXLen;
        crv = jpake_MultipleSecItem2Attribute(key, generatedAttrs, 
                                              NUM_ELEM(generatedAttrs));
    }

    PORT_FreeArena(arena, PR_TRUE);
    return crv;
}
Exemplo n.º 15
0
*/
const uint8_t code_ACCodes[] PROGMEM = {
0x04,
0x94,
0x49,
0x28,
0xA2,
0x92,
0x48,
0x92,
0x89,
0x25,
0x24,
0x52,
0x4E,
0x30
};
const struct IrCode code_ACCode PROGMEM = {
  freq_to_timerval(38462),
  36,		// # of pairs
  3,		// # of bits per index
  code_ACTimes,
  code_ACCodes
};


const struct IrCode *ACpowerCodes[] PROGMEM = {
&code_ACCode };

uint8_t num_ACcodes = NUM_ELEM(ACpowerCodes);
Exemplo n.º 16
0
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
};

// special pointer for reading from ROM memory
PGM_P const largeimage_p PROGMEM = large_image;

#define NUM_ELEM(x) (sizeof (x) / sizeof (*(x)))
int imagesize = NUM_ELEM(large_image);

// this function is called when timer1 compare matches OCR1A
uint8_t j = 0;
SIGNAL( SIG_TIMER1_COMPA ) {
  if (j >= imagesize) 
    j = 0;

  // read the image data from ROM
  PORTB = pgm_read_byte(largeimage_p + j); 
 
  j++;
}

int main(void) {