Example #1
0
static void
do_encrypt_r (char *block, int edflag, struct des_ctx *ctx)
{
  unsigned char bin[8], bout[8];
  pack_bits (bin, block);
  des_crypt_block (ctx, bout, bin, 1, edflag != 0);
  unpack_bits (block, bout);
}
Example #2
0
static void
do_setkey_r (const char *key, struct des_ctx *ctx)
{
  XCRYPT_SECURE_MEMSET (ctx, sizeof (struct des_ctx));
  des_set_salt (ctx, 0);

  unsigned char bkey[8];
  pack_bits (bkey, key);
  des_set_key (ctx, bkey);
}
Example #3
0
int dci_format1_pack(char *packet, struct dci_format1 *data) {
    int i;
    char *buffer = packet;
    int total_len;

    if (data->carrier_indicator_len < 0 || data->carrier_indicator_len > 3) {
        return -1;
    }
    if (data->harq_pnum_len != 3 && data->harq_pnum_len != 4) {
        return -1;
    }

    if (data->carrier_indicator_len) {
        pack_bits(data->carrier_indicator,&buffer,
                  data->carrier_indicator_len);
    }
    if (data->ra_type == TYPE0) {
        pack_bits(0,&buffer,1);
    } else if (data->ra_type == TYPE1) {
        pack_bits(1,&buffer,1);
    }
    if (data->ra_type == NA || data->ra_type == TYPE0) {
        for (i=0; i<data->nof_rbg; i++) {
            pack_bits(data->rbg_mask[i],&buffer,1);
        }
    } else {
        printf("TYPE1 RA not implemented\n");
        return -1;
    }
    pack_bits(data->mcs,&buffer,5);

    pack_bits(data->harq_pnum,&buffer,data->harq_pnum_len);
    pack_bits(data->new_data,&buffer,1);
    pack_bits(data->redundancy_version,&buffer,2);
    pack_bits(data->tpc_command,&buffer,2);

    total_len = (int) (buffer-packet);

    /* TODO:
     * If the number of information bits in format 1 is equal to that for format 0/1A
     * for scheduling the same serving cell and mapped onto the UE specific search space
     * given by the C-RNTI as defined in [3], one bit of value zero shall be appended to format 1.
     */

    total_len = check_ambiguous_size(&buffer,total_len);

    return total_len;
}
Example #4
0
int check_ambiguous_size(char **bits, int nof_bits) {
    int i;
    for (i=0; i<NOF_AMBIGUOUS_SIZES; i++) {
        if (nof_bits == ambiguous_sizes[i]) {
            printf("AMBIGUOUS SIZE %d. Correcting...\n",nof_bits);
            pack_bits(0,bits,1);
            return nof_bits+1;
        }
    }
    return nof_bits;
}
Example #5
0
static void ds_mark_block(struct fileStore * fs, size_t blockNumber, int used) 
{
	unsigned char c;
	int bitSet[8];

	c = fs->used_index[blockNumber / 8];
	unpack_bits(bitSet, c);
	bitSet[blockNumber % 8] = used;
	c = pack_bits(bitSet);

	fs->used_index[blockNumber / 8] = c;
}
Example #6
0
int data_frame_get_bytes(data_frame_t *data_fr, uint8_t *data)
{
    const int nblks = (data_fr->nblks <= 2) ?
        data_fr->nblks : data_fr->nblks - 1;

    memset(data, 0, 8*nblks);
    for (int blk_no = 0; blk_no < nblks; ++blk_no) {
        pack_bits(data, data_fr->data_blks[blk_no].data + 3, 64*blk_no, 64);
    }

    data_frame_reset(data_fr);

    return nblks * 64;
}
Example #7
0
bool
PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
{
	DBGMSG(("> nextBand\n"));

	try {
		BRect bounds = bitmap->Bounds();

		RECT rc;
		rc.left = (int)bounds.left;
		rc.top = (int)bounds.top;
		rc.right = (int)bounds.right;
		rc.bottom = (int)bounds.bottom;

		int height = rc.bottom - rc.top + 1;

		int x = (int)offset->x;
		int y = (int)offset->y;

		int pageHeight = GetPageHeight();

		if (y + height > pageHeight)
			height = pageHeight - y;

		rc.bottom = height - 1;

		DBGMSG(("height = %d\n", height));
		DBGMSG(("x = %d\n", x));
		DBGMSG(("y = %d\n", y));

		if (get_valid_rect(bitmap, &rc)) {

			DBGMSG(("validate rect = %d, %d, %d, %d\n",
				rc.left, rc.top, rc.right, rc.bottom));

			x = rc.left;
			y += rc.top;

			int width = rc.right - rc.left + 1;
			int widthByte = (width + 7) / 8;
				// byte boundary
			int height = rc.bottom - rc.top + 1;
			int in_size = widthByte;
			int out_size = (widthByte * 6 + 4) / 5;
			int delta = bitmap->BytesPerRow();

			DBGMSG(("width = %d\n", width));
			DBGMSG(("widthByte = %d\n", widthByte));
			DBGMSG(("height = %d\n", height));
			DBGMSG(("in_size = %d\n", in_size));
			DBGMSG(("out_size = %d\n", out_size));
			DBGMSG(("delta = %d\n", delta));
			DBGMSG(("renderobj->Get_pixel_depth() = %d\n", fHalftone->GetPixelDepth()));

			uchar* ptr = static_cast<uchar*>(bitmap->Bits())
						+ rc.top * delta
						+ (rc.left * fHalftone->GetPixelDepth()) / 8;

			int compressionMethod;
			int compressedSize;
			const uchar* buffer;

			uchar* in_buffer  = new uchar[in_size];
			uchar* out_buffer = new uchar[out_size];

			auto_ptr<uchar> _in_buffer (in_buffer);
			auto_ptr<uchar> _out_buffer(out_buffer);

			DBGMSG(("move\n"));

			_Move(x, y);
			_StartRasterGraphics(width, height);

			const bool color = GetJobData()->GetColor() == JobData::kColor;
			const int num_planes = color ? 3 : 1;
			
			if (color) {
				fHalftone->SetPlanes(Halftone::kPlaneRGB1);
				fHalftone->SetBlackValue(Halftone::kLowValueMeansBlack);
			}
			
			for (int i = rc.top; i <= rc.bottom; i++) {
			
				for (int plane = 0; plane < num_planes; plane ++) {
										
					fHalftone->Dither(in_buffer, ptr, x, y, width);
							
					compressedSize = pack_bits(out_buffer, in_buffer, in_size);
					
					if (compressedSize + _BytesToEnterCompressionMethod(2)
						< in_size + _BytesToEnterCompressionMethod(0)) {
						compressionMethod = 2; // back bits
						buffer = out_buffer;
					} else {
						compressionMethod = 0; // uncompressed
						buffer = in_buffer;
						compressedSize = in_size;
					}
		
					_RasterGraphics(
						compressionMethod,
						buffer,
						compressedSize,
						plane == num_planes - 1);
				
				}

				ptr  += delta;
				y++;
			}

			_EndRasterGraphics();

		} else
			DBGMSG(("band bitmap is clean.\n"));

		if (y >= pageHeight) {
			offset->x = -1.0;
			offset->y = -1.0;
		} else
			offset->y += height;

		DBGMSG(("< nextBand\n"));
		return true;
	}
	catch (TransportException& err) {
		BAlert* alert = new BAlert("", err.What(), "OK");
		alert->Go();
		return false;
	} 
}