aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/sf2/cells_map.v
blob: 6ad7807d224d403fa3eab6e8b9c3b0a1efdbe4e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module  \$_DFF_N_ (input D, C, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(!C), .EN(1'b1), .ALn(1'b1), .ADn(1'b1), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module  \$_DFF_P_ (input D, C, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(C), .EN(1'b1), .ALn(1'b1), .ADn(1'b1), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_NN0_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(!C), .EN(1'b1), .ALn(R), .ADn(1'b1), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_NN1_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(!C), .EN(1'b1), .ALn(R), .ADn(1'b0), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_NP0_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(!C), .EN(1'b1), .ALn(!R), .ADn(1'b1), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_NP1_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(!C), .EN(1'b1), .ALn(!R), .ADn(1'b0), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_PN0_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(C), .EN(1'b1), .ALn(R), .ADn(1'b1), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_PN1_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(C), .EN(1'b1), .ALn(R), .ADn(1'b0), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_PP0_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(C), .EN(1'b1), .ALn(!R), .ADn(1'b1), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

module \$_DFF_PP1_ (input D, C, R, output Q);
  SLE _TECHMAP_REPLACE_ (.D(D), .CLK(C), .EN(1'b1), .ALn(!R), .ADn(1'b0), .SLn(1'b1), .SD(1'b0), .LAT(1'b0), .Q(Q));
endmodule

// module  \$_DFFE_NN_ (input D, C, E, output Q); SB_DFFNE _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(!E)); endmodule
// module  \$_DFFE_PN_ (input D, C, E, output Q); SB_DFFE  _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(!E)); endmodule
//
// module  \$_DFFE_NP_ (input D, C, E, output Q); SB_DFFNE _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E)); endmodule
// module  \$_DFFE_PP_ (input D, C, E, output Q); SB_DFFE  _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E)); endmodule
//
// module  \$__DFFE_NN0 (input D, C, E, R, output Q); SB_DFFNER _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .R(!R)); endmodule
// module  \$__DFFE_NN1 (input D, C, E, R, output Q); SB_DFFNES _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .S(!R)); endmodule
// module  \$__DFFE_PN0 (input D, C, E, R, output Q); SB_DFFER  _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .R(!R)); endmodule
// module  \$__DFFE_PN1 (input D, C, E, R, output Q); SB_DFFES  _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .S(!R)); endmodule
//
// module  \$__DFFE_NP0 (input D, C, E, R, output Q); SB_DFFNER _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .R(R)); endmodule
// module  \$__DFFE_NP1 (input D, C, E, R, output Q); SB_DFFNES _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .S(R)); endmodule
// module  \$__DFFE_PP0 (input D, C, E, R, output Q); SB_DFFER  _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .R(R)); endmodule
// module  \$__DFFE_PP1 (input D, C, E, R, output Q); SB_DFFES  _TECHMAP_REPLACE_ (.D(D), .Q(Q), .C(C), .E(E), .S(R)); endmodule

`ifndef NO_LUT
module \$lut (A, Y);
  parameter WIDTH = 0;
  parameter LUT = 0;

  input [WIDTH-1:0] A;
  output Y;

  generate
    if (WIDTH == 1) begin
      CFG1 #(.INIT(LUT)) _TECHMAP_REPLACE_ (.Y(Y), .A(A[0]));
    end else
    if (WIDTH == 2) begin
      CFG2 #(.INIT(LUT)) _TECHMAP_REPLACE_ (.Y(Y), .A(A[0]), .B(A[1]));
    end else
    if (WIDTH == 3) begin
      CFG3 #(.INIT(LUT)) _TECHMAP_REPLACE_ (.Y(Y), .A(A[0]), .B(A[1]), .C(A[2]));
    end else
    if (WIDTH == 4) begin
      CFG4 #(.INIT(LUT)) _TECHMAP_REPLACE_ (.Y(Y), .A(A[0]), .B(A[1]), .C(A[2]), .D(A[3]));
    end else begin
      wire _TECHMAP_FAIL_ = 1;
    end
  endgenerate
endmodule
`endif
"n">mNameEdit; TextView mEmailEdit; CheckBox mUploadCheckbox; View mBackButton; View mCreateButton; View mCustomKeyLayout; Button mCustomKeyRevertButton; SaveKeyringParcel mSaveKeyringParcel; private CryptoOperationHelper<UploadKeyringParcel, UploadResult> mUploadOpHelper; private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mCreateOpHelper; private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mMoveToCardOpHelper; // queued results which may trigger delayed actions private EditKeyResult mQueuedSaveKeyResult; private OperationResult mQueuedFinishResult; private EditKeyResult mQueuedDisplayResult; // NOTE: Do not use more complicated pattern like defined in android.util.Patterns.EMAIL_ADDRESS // EMAIL_ADDRESS fails for mails with umlauts for example private static final Pattern EMAIL_PATTERN = Pattern.compile("^[\\S]+@[\\S]+\\.[a-z]+$"); public static CreateKeyFinalFragment newInstance() { CreateKeyFinalFragment frag = new CreateKeyFinalFragment(); frag.setRetainInstance(true); Bundle args = new Bundle(); frag.setArguments(args); return frag; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.create_key_final_fragment, container, false); mNameEdit = (TextView) view.findViewById(R.id.name); mEmailEdit = (TextView) view.findViewById(R.id.email); mUploadCheckbox = (CheckBox) view.findViewById(R.id.create_key_upload); mBackButton = view.findViewById(R.id.create_key_back_button); mCreateButton = view.findViewById(R.id.create_key_next_button); mCustomKeyLayout = view.findViewById(R.id.custom_key_layout); mCustomKeyRevertButton = (Button) view.findViewById(R.id.revert_key_configuration); CreateKeyActivity createKeyActivity = (CreateKeyActivity) getActivity(); // set values if (createKeyActivity.mName != null) { mNameEdit.setText(createKeyActivity.mName); } else { mNameEdit.setText(getString(R.string.user_id_no_name)); } if (createKeyActivity.mAdditionalEmails != null && createKeyActivity.mAdditionalEmails.size() > 0) { String emailText = createKeyActivity.mEmail + ", "; Iterator<?> it = createKeyActivity.mAdditionalEmails.iterator(); while (it.hasNext()) { Object next = it.next(); emailText += next; if (it.hasNext()) { emailText += ", "; } } mEmailEdit.setText(emailText); } else { mEmailEdit.setText(createKeyActivity.mEmail); } checkEmailValidity(); mCreateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createKey(); } }); mCustomKeyRevertButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { keyConfigRevertToDefault(); } }); mBackButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CreateKeyActivity createKeyActivity = (CreateKeyActivity) getActivity(); if (createKeyActivity != null) { createKeyActivity.loadFragment(null, FragAction.TO_LEFT); } } }); // If this is a debug build, don't upload by default if (Constants.DEBUG) { mUploadCheckbox.setChecked(false); } return view; } @Override public void onPrepareOptionsMenu(Menu menu) { CreateKeyActivity createKeyActivity = (CreateKeyActivity) getActivity(); MenuItem editItem = menu.findItem(R.id.menu_create_key_edit); editItem.setEnabled(!createKeyActivity.mCreateSecurityToken); super.onPrepareOptionsMenu(menu); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.create_key_final, menu); super.onCreateOptionsMenu(menu, inflater); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_create_key_edit: Intent edit = new Intent(getActivity(), EditKeyActivity.class); edit.putExtra(EditKeyActivity.EXTRA_SAVE_KEYRING_PARCEL, mSaveKeyringParcel); startActivityForResult(edit, REQUEST_EDIT_KEY); return true; default: return super.onOptionsItemSelected(item); } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (mCreateOpHelper != null) { mCreateOpHelper.handleActivityResult(requestCode, resultCode, data); } if (mMoveToCardOpHelper != null) { mMoveToCardOpHelper.handleActivityResult(requestCode, resultCode, data); } if (mUploadOpHelper != null) { mUploadOpHelper.handleActivityResult(requestCode, resultCode, data); } switch (requestCode) { case REQUEST_EDIT_KEY: { if (resultCode == Activity.RESULT_OK) { SaveKeyringParcel customKeyConfiguration = data.getParcelableExtra(EditKeyActivity.EXTRA_SAVE_KEYRING_PARCEL); keyConfigUseCustom(customKeyConfiguration); } break; } default: super.onActivityResult(requestCode, resultCode, data); } } public void keyConfigUseCustom(SaveKeyringParcel customKeyConfiguration) { mSaveKeyringParcel = customKeyConfiguration; mCustomKeyLayout.setVisibility(View.VISIBLE); } public void keyConfigRevertToDefault() { Activity activity = getActivity(); if (activity == null) { return; } mSaveKeyringParcel = createDefaultSaveKeyringParcel((CreateKeyActivity) activity); mCustomKeyLayout.setVisibility(View.GONE); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // We have a menu item to show in action bar. setHasOptionsMenu(true); if (mSaveKeyringParcel == null) { keyConfigRevertToDefault(); } // handle queued actions if (mQueuedFinishResult != null) { finishWithResult(mQueuedFinishResult); return; } if (mQueuedDisplayResult != null) { try { displayResult(mQueuedDisplayResult); } finally { // clear after operation, note that this may drop the operation if it didn't // work when called from here! mQueuedDisplayResult = null; } } if (mQueuedSaveKeyResult != null) { try { uploadKey(mQueuedSaveKeyResult); } finally { // see above mQueuedSaveKeyResult = null; } } } private static SaveKeyringParcel createDefaultSaveKeyringParcel(CreateKeyActivity createKeyActivity) { SaveKeyringParcel saveKeyringParcel = new SaveKeyringParcel(); if (createKeyActivity.mCreateSecurityToken) { saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 2048, null, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER, 0L)); saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 2048, null, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, 0L)); saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 2048, null, KeyFlags.AUTHENTICATION, 0L)); // use empty passphrase saveKeyringParcel.setNewUnlock(new ChangeUnlockParcel(new Passphrase())); } else { saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 3072, null, KeyFlags.CERTIFY_OTHER, 0L)); saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 3072, null, KeyFlags.SIGN_DATA, 0L)); saveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 3072, null, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, 0L)); if (createKeyActivity.mPassphrase != null) { saveKeyringParcel.setNewUnlock(new ChangeUnlockParcel(createKeyActivity.mPassphrase)); } else { saveKeyringParcel.setNewUnlock(null); } } String userId = KeyRing.createUserId( new KeyRing.UserId(createKeyActivity.mName, createKeyActivity.mEmail, null) ); saveKeyringParcel.mAddUserIds.add(userId); saveKeyringParcel.mChangePrimaryUserId = userId; if (createKeyActivity.mAdditionalEmails != null && createKeyActivity.mAdditionalEmails.size() > 0) { for (String email : createKeyActivity.mAdditionalEmails) { String thisUserId = KeyRing.createUserId( new KeyRing.UserId(createKeyActivity.mName, email, null) ); saveKeyringParcel.mAddUserIds.add(thisUserId); } } return saveKeyringParcel; } private void checkEmailValidity() { CreateKeyActivity createKeyActivity = (CreateKeyActivity) getActivity(); boolean emailsValid = true; if (!EMAIL_PATTERN.matcher(createKeyActivity.mEmail).matches()) { emailsValid = false; } if (createKeyActivity.mAdditionalEmails != null && createKeyActivity.mAdditionalEmails.size() > 0) { for (Iterator<?> it = createKeyActivity.mAdditionalEmails.iterator(); it.hasNext(); ) { if (!EMAIL_PATTERN.matcher(it.next().toString()).matches()) { emailsValid = false; } } } if (!emailsValid) { mEmailEdit.setError(getString(R.string.create_key_final_email_valid_warning)); mEmailEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNameEdit.requestFocus(); // Workaround to remove focus from email } }); } } private void createKey() { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); if (activity == null) { // this is a ui-triggered action, nvm if it fails while detached! return; } final boolean createSecurityToken = activity.mCreateSecurityToken; CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult> createKeyCallback = new CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult>() { @Override public SaveKeyringParcel createOperationInput() { return mSaveKeyringParcel; } @Override public void onCryptoOperationSuccess(EditKeyResult result) { if (createSecurityToken) { moveToCard(result); return; } if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) { // result will be displayed after upload uploadKey(result); return; } finishWithResult(result); } @Override public void onCryptoOperationCancelled() { } @Override public void onCryptoOperationError(EditKeyResult result) { displayResult(result); } @Override public boolean onCryptoSetProgress(String msg, int progress, int max) { return false; } }; mCreateOpHelper = new CryptoOperationHelper<>(1, this, createKeyCallback, R.string.progress_building_key); mCreateOpHelper.cryptoOperation(); } private void displayResult(EditKeyResult result) { Activity activity = getActivity(); if (activity == null) { mQueuedDisplayResult = result; return; } result.createNotify(activity).show(); } private void moveToCard(final EditKeyResult saveKeyResult) { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; CachedPublicKeyRing key = (new ProviderHelper(activity)) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "Key that should be moved to Security Token not found in database!"); return; } // define subkeys that should be moved to the card Cursor cursor = activity.getContentResolver().query( KeychainContract.Keys.buildKeysUri(changeKeyringParcel.mMasterKeyId), new String[]{KeychainContract.Keys.KEY_ID,}, null, null, null ); try { while (cursor != null && cursor.moveToNext()) { long subkeyId = cursor.getLong(0); changeKeyringParcel.getOrCreateSubkeyChange(subkeyId).mMoveKeyToSecurityToken = true; } } finally { if (cursor != null) { cursor.close(); } } // define new PIN and Admin PIN for the card changeKeyringParcel.mSecurityTokenPin = activity.mSecurityTokenPin; changeKeyringParcel.mSecurityTokenAdminPin = activity.mSecurityTokenAdminPin; CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult> callback = new CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult>() { @Override public SaveKeyringParcel createOperationInput() { return changeKeyringParcel; } @Override public void onCryptoOperationSuccess(EditKeyResult result) { handleResult(result); } @Override public void onCryptoOperationCancelled() { } @Override public void onCryptoOperationError(EditKeyResult result) { handleResult(result); } public void handleResult(EditKeyResult result) { // merge logs of createKey with moveToCard saveKeyResult.getLog().add(result, 0); if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) { // result will be displayed after upload uploadKey(saveKeyResult); return; } finishWithResult(saveKeyResult); } @Override public boolean onCryptoSetProgress(String msg, int progress, int max) { return false; } }; mMoveToCardOpHelper = new CryptoOperationHelper<>(2, this, callback, R.string.progress_modify); mMoveToCardOpHelper.cryptoOperation(new CryptoInputParcel(new Date())); } private void uploadKey(final EditKeyResult saveKeyResult) { Activity activity = getActivity(); // if the activity is gone at this point, there is nothing we can do! if (activity == null) { mQueuedSaveKeyResult = saveKeyResult; return; } // set data uri as path to keyring final long masterKeyId = saveKeyResult.mMasterKeyId; // upload to favorite keyserver final String keyserver = Preferences.getPreferences(activity).getPreferredKeyserver(); CryptoOperationHelper.Callback<UploadKeyringParcel, UploadResult> callback = new CryptoOperationHelper.Callback<UploadKeyringParcel, UploadResult>() { @Override public UploadKeyringParcel createOperationInput() { return new UploadKeyringParcel(keyserver, masterKeyId); } @Override public void onCryptoOperationSuccess(UploadResult result) { handleResult(result); } @Override public void onCryptoOperationCancelled() { } @Override public void onCryptoOperationError(UploadResult result) { handleResult(result); } public void handleResult(UploadResult result) { saveKeyResult.getLog().add(result, 0); finishWithResult(saveKeyResult); } @Override public boolean onCryptoSetProgress(String msg, int progress, int max) { return false; } }; mUploadOpHelper = new CryptoOperationHelper<>(3, this, callback, R.string.progress_uploading); mUploadOpHelper.cryptoOperation(); } public void finishWithResult(OperationResult result) { Activity activity = getActivity(); if (activity == null) { mQueuedFinishResult = result; return; } Intent data = new Intent(); data.putExtra(OperationResult.EXTRA_RESULT, result); activity.setResult(Activity.RESULT_OK, data); activity.finish(); } }